I am trying to create a regex for a list of accepted symbols and character string

I am building a test function that should only accept the following:

CR – only once not with DB
DB – only once not with CR

I have gotten the first few to work like so: new RegExp(/^([-*+.,$9ZVB]|CR|DB)*$/gm), but I annot get the regex to only allow the CR or DB to appear only once either at beginning or end of the string. Any suggestions?

Test at

Stack Overflow Asked on November 15, 2021

2 Answers

2 Answers

I'm guessing you are using javascript.

You can use the regex:


Demo & explanation

var test = [
console.log( (a) {
  return a+' : '+/^(?:(?:CR|DB)[-*+.,$9ZVB]+|[-*+.,$9ZVB]+(?:CR|DB))$/.test(a);

Answered by Toto on November 15, 2021

Try this expression:




You can test it here:

Answered by Ilya Lysenko on November 15, 2021

Add your own answers!

Related Questions

javascript get Pacific Timezone

1  Asked on December 7, 2020


Why define a struct with single private field of unit type?

1  Asked on December 6, 2020 by m-bat


Read more Laravel

1  Asked on December 6, 2020 by user11916445


npx: the shell-auto-fallback argument has been removed

2  Asked on December 6, 2020 by mike-earley


Cross-Process Memory Filesystem In Python

0  Asked on December 6, 2020 by eliran-abdoo


HTML Template not rendering on screen

1  Asked on December 6, 2020 by ojm


WOE in a magrittr Pipe

2  Asked on December 6, 2020 by gojomoso


Convert object of arrays to array of objects

1  Asked on December 5, 2020 by drmrbrewer


Remove item from state

3  Asked on December 5, 2020 by clayton-crockville


How to concatenate 3 lists even if there are a list null?

2  Asked on December 5, 2020 by alexz


Angular 8: Select first element of ng-content

1  Asked on December 5, 2020 by ijustdev


docker-compose volume empty

3  Asked on December 5, 2020 by kerby82


Ask a Question

Get help from others!

© 2021 All rights reserved.