+ 6
Help with Regular Expressions
I want to find this in strings: %RED% %BLUE% %JEKFJ% etc. I tryed with: /%+[a-zA-Z]+%/ /(%+[a-zA-Z]+%)/ /((%{1})+[a-zA-Z]+(%{1}))/ But it, or don't work, or select strings with more than one "%", for example "%%RED%"
7 ответов
+ 1
InvBoy [ :: FEDE :: ] you can see it in the code. If you need to match a string with exact start and end use the tokens for start =>"^" and end =>"quot;. Hope it helps you 😉.
https://code.sololearn.com/WS4mwwYKoy0x/?ref=app
+ 2
Try (%[a-zA-z]+%), worked fine for me :)
+ 2
/%[A-Z]+%/ will match all of these.
If you want to exclude items with two %% for example, your need to tell the regex engine what to expect before the %. If you just don't want to allow %% at the beginning, then use this:
/(?:[^%])%[A-Z]+%/
+ 2
Don't listen to Cbr✔[ Most active ]
That answer is wrong despite the upvotes!?
Would only match 1 character between the % -- total nonsense.
0
As you need to find specific words and characters that are known, I think you can use the following regex: \%(RED|BLUE|JEKFG)\%
Here the code:https://code.sololearn.com/c6JlVeLwr05h/?ref=app