Hello,
I was wondering if you may be able to help me with the following regex problems please?
I use https://regex101.com to check my regexes.
The first one is:
/[A-z0-9.=?:()\s]+/g
This is to only allow any-cased letters, numbers and the . ? : ( ) characters and spaces.
However, this regex also matches a backslash. Probably other characters but I haven’t checked. How come?
The second one is:
I’m trying to match question marks or colons only if they are wrapped in apostrophes or speech marks.
(([^’])(?|:)([^’]))
My attempts are just all over the place. I’ve tried various versions of the above, even tried using \B and \b.
I should see a match on something like this:
‘some text here ?: these are matched’ some text here ?: these are NOT matched “some text here ?: these are matched”
Although I see it’s going to be awkward to make the regex ignore text between the two some text here [color=blue]?:[/color] these are matched statements.
My PHP book and the Internet are not revealing the answer so far!
A bit of background:
This is part of the first class I’m writing to make calls to my database. One of the parameters my constructor accepts is $numberOfBinds, i.e. how many values will be bound to the PDO statement.
The second regex is to check that the number of binds matches the number of ?'s or :parameters that are not contained within apostrophes or speech marks in the SQL.
I’ve always liked doing things the hard way! I figure it gives me a broader knowledge as I rampantly trawl through Google for hours before giving up and coming here