I can get the vars, but not the values.
I tried many many regex, but still nothing.
\=\"?(.*?)\"? is supposed to extract what's after "=" with or without quotes, right?
Thanx, working here, but what if I want more than just a-z0-9 as a value?
I will have some commas and special chars sometime... like javascript code, or accents.
I still don't understand why it's not working with (.*?)
zenhop wrote:It works if quotes are mandatory, but if I put the quote as an option, it does not work anymore.
Maybe a problem in putting the quotes optionals?
My regex was #([a-z0-9]+)\=\"?(.*?)\"?#mis but not working.
It's working for only alphanumeric values: #([a-z1-9]+)\s*=\"?([a-z1-9]+)\"?#mis
So what is wrong?
Juts changing ([a-z1-9]+) for (.*?) is making the whole regex not working.
By making everything reluctant after your "=" sign (the quotes and the DOT-STAR), the regex engine will not match anything. But, I don't know if that the case with you. Your current problem description is "it does not work anymore", which is a bit vague, IMO.
Perhaps you could provide a couple of input strings that you need to match and clearly indicate which ones don't get matched by your current regex.
Well, with that last regex (dot-star + optional quote) I can get the vars, but not the values. All values are empty.
The dot-star does not match anything.
My goal is just to get the vars and values of a string representing the attributes of an html tag. The vars are only alphanumerics so no problems to get them, but the values are not just alphanumerics, they can contain anything: javascript, accents, special chars...
But some of the values are not surrounded by 2 quotes, so the 2 quotes are optionals. It's the case when the value is just one word or numeric for example.
So, after the "=", I either have a complex value between quotes, or a single alphanumeric string like a word or a number.
Note that inside a character class, the normal meta character, like the exclusive OR (the pipe), does not meam OR, but matches just the pipe character itself.
So, ["|\s] matches a '"', '|' or a white space character.
I guess the OP is looking for something like this: