Skip to content

Tag: regex

Regex to find content of the last occurence of square brackets

Hi Everybody, I’m Currently using preg_match and I’m trying to extract some informations enclosed in square brackets. So far, I have used this: /[(.*)]/ But I want it to be only the content of the last occurence – or the first one, if starting from the end! In the following: string = “…

How to search in an array with preg_match?

How do I search in an array with preg_match? Example: Answer In this post I’ll provide you with three different methods of doing what you ask for. I actually recommend using the last snippet, since it’s easiest to comprehend as well as being quite neat in code. How do I see what elements in an arr…

Regular expression matching for entire string

I’m very new to PHP. I need to check whether a given string has characters from a given set, say {a, b, c}. So, I am trying regular expressions. “(abc)+” should do the trick. However, looking at the manual entries for preg_match and associated functions, I noticed that these functions perfor…

New line to paragraph function

I have this interesting function that I’m using to create new lines into paragraphs. I’m using it instead of the nl2br() function, as it outputs better formatted text. } The problem is that whenever I try to create a single line break, it inadvertently removes the first character of the paragraph …

scrape data using regex and simplehtmldom

i am trying to scrape some data from this site : http://laperuanavegana.wordpress.com/ . actually i want the title of recipe and ingredients . ingredients is located inside two specific keyword . i am trying to get this data using regex and simplehtmldom . but its showing the full html text not just the ingre…

Replace spaces around hyphens with nbsp

I’m in need of (probably) regexp (or two) to do following: replace every space after any single letter word with   I found this question, however, if there’s word with apostrophe (like there’s), previous regexp ‘thinks’ that the ‘s’ after the apostrophe is si…