Regular expression to get string between single or double quotes even if it is empty
P粉554842091
P粉554842091 2024-04-01 17:28:41
0
1
407

Here's the regex I'm trying:

/((?<![\\])['"])((?:.(?!(?<![\\])\1))*.?)\1/

This is the text I gave

val1=""val2>"2022-11-16 10:19:20"

I also need a blank expression like val1, i.e. I need something like the following in my contest

""
2022-11-16 10:19:20

If I change the text to look like below I will get the correct output

val2>"2022-11-16 10:19:20"val1=""

Can anyone tell me what's wrong with me

P粉554842091
P粉554842091

reply all(1)
P粉064448449

Use alternatives to match both cases.

One alternative matches a pair of quotes, another uses lookahead to match the inside of two quotes.

""|(?<=")[^"]+(?=")
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!