Pergunta

I am using IOS regular expression engine to match any text in the form:

"[h1]test text[/h1]"

i wrote: @"\\[h1]([^.]*)[/h1\\]]"

to match this form, but it is working sometimes and other times it matches text out of bound of the last bracket, is it the best form to match these strings or what you suggest ?

Foi útil?

Solução

I would recommend using (.*?) instead of ([^.]*?).

It looks want you want is "between [h1] and [/h1] match anything." That would be (.*?). What you have is "between [h1] and [/h1] match anything which is not a period (.)."

In addition, you have a problem with your ending [/h1\\]] means end with a /, h, 1, or ]. I think you want \\[/h1] which means end with the string [/h1].

The final regex would be @"\\[h1](.*?)\\[/h1]".

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top