Reputation: 1186
I plan to allow reader to create links in a custom way. I think it will be easier for the ones who are not used to write html opening+closing tags.
++visible text part==invisible address part++
a valid structured example:++stack overflow==http://stackoverflow.com/questions/ask++
Of course a user can input more than 1 link.
++visible text part==invisible address part++
So I require your help for the preg_match
pattern
to verify the custom linking structure. Please also be aware that I will need 2 parts (that are:left part of ==
visible text part AND right part of ==
invisible address part matched seperately for my 2nd and 3rd requirements.
/++(.+)==(.+)++/
thanks, BR
Upvotes: 0
Views: 257
Reputation: 13631
Try
/\+\+(.+?)==(.+?)\+\+/
+
is a regex special character and should be escaped.
Add s
after the ending delimiter /
if you want the match to include newline characters.
Upvotes: 2
Reputation: 10638
There are two major problems with your regex. First of all +
is a reserved sign as you know (since you use it), so you have to escape it.
That would bring us to the following regex: /\+\+(.+)==(.+)\+\+/
If you use it, it might actually work, but only if the markup is used never or once, that is because regex in PHP is greedy. You can solve that by using the right modifier.
This brings us to /\+\+(.+)==(.+)\+\+/U
which is not perfect but will work. You can then do other improvements regarding (.+)
Upvotes: 1