I am trying to catch a series of tags with regex:
/<shi>(\n|<shi\n>/
How do I match the cases below:
<shi><\nshi><\nshi\n><shi\n\n>
... (And more cases like that)
CodePudding user response:
/<\n*shi\n*>/ should do the job.
Let's see why:
<will match the character<once\n*will match the newline character between 0 and unlimited times (greedy)shiwill match the charactersshiliterally (case sensitive)\n*will match the newline character between 0 and unlimited times (greedy)>will match the character>once
@NNL993's answer (<(\n )?shi(\n )?>) also works, but it uses capturing groups.
\nwill match the newline characterwill match the previous token (newline character) between one and unlimited times (greedy)?will match the previous token ((\n )group) between zero and one time
