Skip to content

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…

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…

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 countri…

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 hyper…