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
4
votes
1 answer

RegEx and split camelCase

I want to get an array of all the words with capital letters that are included in the string. But only if the line begins with "set". For example: - string "setUserId", result array("User", "Id") - string "getUserId", result false Without…
Tui Kiken
  • 205
  • 2
  • 8
4
votes
1 answer

Grab/download images from multiple pages using php preg_match_all & cURL

So I'm trying to grab some images from another site, the problem is each image is on a different page IE: id/1, id/2, id/3 etc etc so far I have the code below which can grab an image from the single URL given using: $returned_content =…
Dizzi
  • 749
  • 2
  • 11
  • 21
4
votes
8 answers

Limit the number of results using preg_match_all PHP

Is there any way to limit the number of matches that will be returned using preg_match_all? So for example, I want to match only the first 20

tags on a web page but there are 100

tags. Cheers

Franco
  • 2,846
  • 7
  • 35
  • 54
4
votes
3 answers

PHP - preg_replace items in brackets with array items

I have an array: array('id' => 'really') I have a string: $string = 'This should be {id} simple.'; I want to end up with: This should be really simple. I have a regular expression that will work with the {id} aspect, but I am having a hard time…
manumoomoo
  • 2,707
  • 3
  • 24
  • 25
4
votes
4 answers

How to exclude text between two curly brackets with regex?

I am new to regular expressions, I have a text like this: test{{this should not be selected and the curly brackets too}} but this one { or } should be selected. So I want to exclude all text between an opening and closing curly brackets. and…
Mana
  • 167
  • 3
  • 13
4
votes
2 answers

Find all substrings within a string with overlap

Hi im trying to find all overlapping substrings in a string here is my code its only finding nonrepeating ACA. $haystack = "ACAAGACACATGCCACATTGTCC"; $needle = "ACA"; echo preg_match_all("/$needle/", $haystack, $matches);
lolsharp
  • 69
  • 1
  • 11
4
votes
1 answer

preg_match_all() not matching all possible occurrences

I have binary pattern "10000101001" and I want to match string having 0 in starting and ending 1. So for above given example there should be 3 possible match 100001, 101, 1001. Below is the sample code I am trying: function solution() { $length…
Manoj Saini
  • 108
  • 4
4
votes
2 answers

extract chords from a tab using PHP

I'm loosing my hairs trying to figure out how to parse a music (text) tab using preg_match_all and PREG_OFFSET_CAPTURE. Example input : [D#] [G#] [Fm] [C#] [Fm] [C#] [Fm] [C#] [Fm] [C]La la la la la la [Fm]la la la la [D#] [Fm]I made this song…
gordie
  • 1,637
  • 3
  • 21
  • 41
4
votes
5 answers

PHP: How to split a string by dash and everything between brackets. (preg_split or preg_match)

I've been wrapping my head around this for days now, but nothing seems to give the desired result. Example: $var = "Some Words - Other Words (More Words) Dash-Binded-Word"; Desired result: array( [0] => Some Words [1] => Other Words [2] => More…
Sascha
  • 141
  • 1
  • 8
4
votes
2 answers

Regex match section within string

I have a string foo-foo-AB1234-foo-AB12345678. The string can be in any format, is there a way of matching only the following pattern letter,letter,digits 3-5 ? I have the following implementation: preg_match_all('/[A-Za-z]{2}[0-9]{3,6}/', $string,…
user1320260
4
votes
2 answers

PHP regex strip comma and space from beginning and end of string

I have some strings like this ", One " ", One , Two" "One, Two " " One,Two, " " ,Two ,Three " EDIT 2: Some strings have two words between coma like ", Two ,Three, Twenty Five, Six". and need to remove space and or comma at the beginning and end of…
Roman Toasov
  • 747
  • 11
  • 36
4
votes
1 answer

php multiline preg_match_all

I have following code: $content = <<{wrapper btnlabel="AAA"}zzzzzzzzzzzzzzzzzzzz{/wrapper}

{wrapper btnlabel="Text"}

123 1 123 12 123 3…
Tony
  • 5,797
  • 3
  • 26
  • 22
4
votes
2 answers

Php regular expression to match a div

This is mycode
Thoman
  • 742
  • 2
  • 9
  • 20
4
votes
3 answers

PHP RegEx with or without trailing slashes

My goal: To capture the last part of a URL whether there is or isn't a trailing slash, without the trailing slash being a part of the string on a URL similar to the one following: http://foo.com/p/dPWjiVtX-C/ ^^^^^^^^^^ …
grepsedawk
  • 3,324
  • 2
  • 26
  • 49
4
votes
3 answers

Match pattern and exclude substrings with preg_match_all

I need to find all the strings placed between START and END, escluding PADDING substring from matched string. The best way I've found is $r="stuffSTARTthisPADDINGisENDstuffstuffSTARTwhatPADDINGIwantPADDINGtoPADDINGfindENDstuff"…
Emilio
  • 3,901
  • 11
  • 44
  • 50