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 = “…
Tag: regex
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…
Split string on dots not preceded by a digit without losing digit in split
Given the following sentence: I want preg_split() to give this: I am using: But this gives me: As you can see, the last character of each sentence is removed. I know why this happens, but I don’t know how to prevent it from happening. Any ideas? Can lookaheads and lookbehinds help here? I am not really …
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 …
Php Sanitize and Validate form with some character exceptions
I’m using in Php Sanitize and Validate Filters but I have problems to add some rules, I have some basic knowledge of php so I think this question is easy for you. I need to add a minimum and maximum number of characters (14-15) and I want to accept this characters ( – or space ) .The exact sequenc…
Split string on non-alphanumeric characters and on positions between digits and non-digits
I’m trying to split a string by non-alphanumeric delimiting characters AND between alternations of digits and non-digits. The end result should be a flat array of consisting of alphabetic strings and numeric strings. I’m working in PHP, and would like to use REGEX. Examples: ES-3810/24MX should be…
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…
PHP: Regex match string not preceeded by a dollar sign
In my syntax highlighter, I use regex to parse different terms. Below is how I parse PHP classes: Now, just ignore the PHP class and the _getHtmlCode function. The regex, “/b{$class}b/”, matches names such as count. If I make a variable named $count, it matches that was well. How can I look for cl…