Questions tagged [preg-match-all]

A PHP function that performs a global regular expression match using PCRE patterns.

A PHP function that performs a global regular expression match using PCRE patterns.

int preg_match_all ( 
     string $pattern , 
     string $subject 
     [, array &$matches 
     [, int $flags = PREG_PATTERN_ORDER 
     [, int $offset = 0 ]]] 
)

preg_match_all() in the PHP Manual

1934 questions
3
votes
4 answers

Count occurrences of specific word after a different, specific word is found

I am rather new to regex and am stuck on the following where I try to use preg_match_all to count the number of hello after world. If I use "world".+(hello), it counts to the in the last hello; "world".*?(hello) stops in the first hello, both giving…
limestreetlab
  • 173
  • 1
  • 11
3
votes
4 answers

Using a regular expression to extract URLs from links in an HTML document

I need to capture all links in a given html. Here is sample code:
... some code goes here ... link 1 link 2 link 3
Valour
  • 773
  • 10
  • 32
3
votes
4 answers

Get number from a string

I have a string for example "lorem 110 ipusm" and I want to get the 110 I already tried this: preg_match_all("/[0-9]/", $string, $ret); but this is returning this: Array ( [0] => 1 [1] => 1 [2] => 0 ) I want something like…
Mokus
  • 10,174
  • 18
  • 80
  • 122
3
votes
1 answer

How to preg_match_all on German Umlauts [äöü]?

If a text has German Umlauts [äöü] the result of preg_match_all has wrong offsets (it seems each Umlaut extend the offset by 1) I need the position of each word, because they will be replaced by other strings. With this tool…
Peter Gast
  • 33
  • 3
3
votes
2 answers

Regex to check the existence of a string in another string

I'm trying to see the existence of /target- in a string of /dir1/dir2/dir3/dir4/../dir7/dir8/dir9/target-.a-word1-word2-alphanumberic1-alphanumberic2.md). $re = '/^(.*?)(\/target-)(.*?)(\.md)$/i'; $str =…
Emma
  • 27,428
  • 11
  • 44
  • 69
3
votes
2 answers

PHP preg_match_all regular expression to get pixel values (with "px") from css

I'm looking for a regular expression for use with PHP's preg_match_all() function, which will give me all of the px values from a CSS file. For example, if the css below is used, then the expected result would be an array of: array ( "11px",…
Darren Gates
  • 473
  • 2
  • 18
3
votes
1 answer

How to find an exact match using regex in PHP?

I have some problems when trying to make a match with my URL with my regex pattern in PHP. my regex: /article/([0-9A-Za-z]++)/post/([0-9A-Za-z-_]++) public function matches(Route $route){ $uri = filter_var(strip_tags($_SERVER['REQUEST_URI']),…
JuanLT
  • 53
  • 1
  • 6
3
votes
2 answers

Why does preg_match_all break with this regex?

I've been struggling with a mystery crash most of today which I have finally resolved but don't really understand my own fix. The purpose of the code is to replace placeholders in a template. Below is the final minimum PHP code I need to reproduce…
3
votes
1 answer

preg_match_all , get all img tag that include a string

this code get all img tags preg_match_all('/]+>/i',$a,$page); but I want get tags that their filenames includes "next.gif" or "pre.gif" for example : $page = ' icon
lachekar
  • 287
  • 1
  • 3
  • 5
3
votes
2 answers

Find two different substr in PHP

From: $str = "This is one string with this picture pic1.jpg and here there's another one pic2.png for example" I want to use something similar to preg_match_all() but I would like to do it just in one line. I want to have in just one array both:…
Max García
  • 149
  • 1
  • 7
3
votes
1 answer

need some help on regex in preg_match_all()

so I need to extract the ticket number "Ticket#999999" from a string.. how do i do this using regex. my current regex is working if I have more than one number in the Ticket#9999.. but if I only have Ticket#9 it's not working please help. current…
Rabb-bit
  • 805
  • 12
  • 24
3
votes
4 answers

How to match words with common prefix in PHP?

I need to write a regex to match the word. To find exact word can be done using /\bword\b/ pattern. But I want the pattern to find word, words, wording and so on. for example i want to write a pattern to find terms account, accounting, accounts and…
daron
  • 33
  • 4
3
votes
3 answers

How do I define the starting line for preg_match in PHP?

Im using the preg_match to find a certain word in a text file. However, I want to define the starting line from which preg_match starts its search. How can I make preg_match to ignore the first 5 lines? Additionally, I have a code which will…
A. McMount
  • 141
  • 6
3
votes
2 answers

php - how to get specific value from the string

I am facing issue when trying to extract specific value from the string but not getting the proper output. $string = com.xyz.ghop.service.sprint.Sprint@1b0258c[id=257,rapidViewId=94,state=CLOSED,name=Alert Success…
Dython
  • 134
  • 4
  • 12
3
votes
2 answers

How to get the words that start with '#' in string using php?

I have this sentence "My name's #jeff,what is thy name?" And now i want to get #jeff from this sentence. I have tried this code for ($i=0; $i <=substr_count($Text,'#'); $i++) { $a=explode('#', $Text); echo $a[$i]; } But it returns…
Papaa
  • 108
  • 10