0

I'm trying to match all parenthesis or quotes AND/OR the pattern ##.*## (so I can remove them all in 1 call). I thought [\(\)\"]* | ##.*## would do the trick. RegExp tester says

[\(\)\"]* | ##.*##
/
gm
1st Alternative [\(\)\"]* 
Match a single character present in the list below [\(\)\"]*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\( matches the character ( literally (case sensitive)
\) matches the character ) literally (case sensitive)
\" matches the character " literally (case sensitive)
  matches the character   literally (case sensitive)
2nd Alternative  ##.*##
 ## matches the characters  ## literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
## matches the characters ## literally (case sensitive)

which also looks like it should work, but given strings like

  • (
  • ()
  • ""
  • ##VAL##
  • `" ##XXX## ) "

NOTHING matches. Each of the patterns on their own match the corresponding strings, but when I put them together, not so much. I'm guessing it's got to be my | operator, but that's where I get in a little over my head.

Can anyone shed some light for me? Thx!!

Daveh0
  • 952
  • 9
  • 33
  • 1
    `[()"]+|##.*?##`? – Wiktor Stribiżew Nov 17 '19 at 16:27
  • as said in the RegExp tester: matches the character literally (case sensitive) – Turo Nov 17 '19 at 16:37
  • The question is why it doesn't work right? It's not how to combine regex. Which there really is no such thing or method, so being a duplicate of something without an answer is ridiculous @ WiktorStribiżew. –  Nov 17 '19 at 16:56
  • The reason _your_ regex doesn't work is that `[\(\)\"]*` will be matched _every single time_ and this `##.*##` will _never_ be matched. When any item in an alternation is optional `*` and is _first_, the match will be satisfied with nothing as well as what's in the class if it finds that. When _nothing_ is matched, all engines increment the current position for the next match, until it iteratively reaches the end of the string. The fix is to make it _non-optional_ with a `+` –  Nov 17 '19 at 17:03

0 Answers0