Skip to content
Advertisement

Tag: regex

regex to isolate javascript using preg_replace_callback

My [php executed] regex is terrible and I’m struggling with trying to isolate javascript scripting within HTML blocks. I have the following regex that works partially, but it’s run into a problem if there’s the word “on” in the text (as opposed to in a < tag >). I think the issue is that the bon…. part needs to be

How to get the values only if all the keys have matched?

I want to make a method that returns keys and values. But only if the keys include the following string “_1” and “__last”. If only one matches then exit the function, only if the two string are included in the key, return the key with the value for a weather. Answer You are making your life so much more difficult

Match Country in String, split based on result

I have a CSV file with one of the fields holding state/country info, formatted like: “Florida United States” or “Alberta Canada” or “Wellington New Zealand” – not comma or tab delimited between them, simply space delimited. I have an array of all the potential countries as well. What I am looking for, is a solution that, in a loop, I

PHP Regex Match ! or * anywhere in string

I’m a beginner in using Regex and have been struggling to create a pattern that can search for a single match of either ! or * anywhere in my string. The full requirements I am looking for are: Start with a letter Contain at least 1 number Between 8-16 characters Contain at least one ! or * What I have

php DOMDocument preg_replace fail detect

Basically, I want to replace content with hyperlink when detected matching keyword tag. the replace need to be outside of caption/image/figure/figcaption/iframe/a of existing content, because putting hyperlink inside these will causing format breaking. my php Now I facing 2 issue want to exclude replace hyperlink tag into but it fail on regex.. currently it display like this… this DOMDocument loadHTML

Decomposing a string into words separared by spaces, ignoring spaces within quoted strings, and considering ( and ) as words

How can I explode the following string: into I would like to extend the boolean fulltext search SQL query, adding the feature to specify specific columns using the notation column:value or column:”valueA value B”. How can I do this using preg_match_all($regexp, $query, $result), i.e., what is the correct regular expression to use? Or more generally, what would be the most

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

Advertisement