Skip to content
Advertisement

Tag: preg-match

PHP preg_match not working as Input pattern

So I have this input pattern in HTML: <input name=”firstnamereg” type=”text” pattern=”[/p{L}+/u ]+”> But When I use the preg_match it does not work: $regexFirstANDLastname = “/[/p{L}+/u ]+/”; preg_match($regexFirstANDLastname, $_POST[“firstnamereg”]); Answer You need to use This pattern, in Chrome and Firefox, will be compiles as a new RegExp(“^(?:[\p{L}\s]+)$”, “u”) regex object. The u flag is used by default, you do not

PHP Preg_match for authorized characters

i’m a noob in regular expressions. Il would like to prevent a form for special characters. The characters auhorized are : I made a preg_match rule that makes problems I know that i should encapsulate special chars but i didn’t know to achieve this. Can you help me please ? Thanks in advance. Answer You can use Note: Using double

preg_match string from meta name

I want to preg_match number “20,956” from $url1 and number “2,894,865” from $url2 $url1: $url2: Tried this to work for both of urls, it works for only $url1 but not in $url2 Any Idea to make it work for both $url1&2? Answer You can use See the regex demo. Details: d – a digit [,d]* – zero or more commas/digits

Weird PHP Regex Preg_Match Bug?

My PHP version is PHP 7.2.24-0ubuntu0.18.04.7 (cli). However it looks like this problem occurs with all versions I’ve tested. I’ve encountered a very weird bug when using preg_match. Anyone know a fix? The first section of code here works, the second one doesn’t. But the regex itself is valid. For some reason the something_happened word is causing it to fail.

PHP Regex Match Specific Pattern between Quotes

I have strings with the following pattern: adfadfadfadfadfadfafdadfa”externalId”:”UCEjBDKfrqQI4TgzT9YLNT8g”afadfadfafadfdaffzfzfzxf Basically, I need to find “externalId” and extract it’s value in between the quotes that follow. The length of the value can change so it needs to be everything inside the two quotes. In this case the desired outcome is to return: Here’s what I have so far: I tried Advanced HTML

Advertisement