I'd like to implement a string check with a regular expression, but it doesn't work and let me ask you a question.
hoge2When I try to write a regular expression that just matches exactly, the following works.
const r ='^ (hoge | hoge2) $' const rr = new RegExp (r,'g') console.log ('hoge'.match (rr)) console.log ('hoge2'.match (rr)) console.log ('hoge3'.match (rr)) //->Array ["hoge"] //->Array ["hoge2"] //->null
However, this time
@ hoge2I wrote the following to make it an exact match, but it doesn't work
const r ='@ ^ (hoge | hoge2) $' const rr = new RegExp (r,'g') console.log ('@ hoge'.match (rr)) console.log ('@ hoge2'.match (rr)) console.log ('@ hoge3'.match (rr)) //->null //->null //->null
If anyone knows how to write it and it will respond correctly, please let me know.
Answer # 1
@After the beginning of the string (
^ ^) Can never come, so this regex never matches.
- python - do not match only when the previous is "_" in the regular expression
- [vba] matches a regular expression that does not match
- c # - regular expression 0 or 1 match
- c # - judging the regular expression () by match method
- php - what is the best delimiter when writing a url as a regular expression?
- format to identify the case where "\" is included in the character enclosed by the regular expression
- regular expressions - the regular expression cannot be deciphered
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory