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
5
votes
3 answers

How to exclude a symbol within [ ] with RegEx

I am using PHP preg_match_all, and this is what I can get so far.... [A-Za-z+\W]+\s[\d] The only problem is that I need the \W to not be a ". So I have tried: [A-Za-z+[^\dA-Za-z"]\s?]+\s[\d] [A-Za-z+]\s?+[^A-Za-z\d"]?\s[\d] among other things,…
Ryan Ward Valverde
  • 6,458
  • 6
  • 37
  • 48
5
votes
2 answers

Preg_match_all returning array within array?

I am trying to get the information out of this array, but for some reason it is nesting everything into $matches[0]. Is this…
Ryan Ward Valverde
  • 6,458
  • 6
  • 37
  • 48
5
votes
2 answers

Matching all numbers with regex using preg_match_all

I have a text, and try to add link to every number of size 3 in it. I use preg_match_all with a pattern: (^|[^\d])(\d{3})($|[^\d]) Grouping is used here to add links only to numbers, not to their neighbors. Test cases are: a 123 234 b - Has to…
Andrey
  • 853
  • 9
  • 27
5
votes
1 answer

Get number from a string after specific character and convert that number

I need a help in regex php. If in a string find number after some character. get that number and replace it with after applying math. Like currency convert. I applied this regex https://regex101.com/r/KhoaKU/1 ([^\?])AUD (\d) regex not correct I…
Lemon Kazi
  • 3,308
  • 2
  • 37
  • 67
5
votes
3 answers

split string by spaces and colon but not if inside quotes

having a string like this: $str = "dateto:'2015-10-07 15:05' xxxx datefrom:'2015-10-09 15:05' yyyy asdf" the desired result is: [0] => Array ( [0] => dateto:'2015-10-07 15:05' [1] => xxxx [2] => datefrom:'2015-10-09 15:05' [3] =>…
caramba
  • 21,963
  • 19
  • 86
  • 127
5
votes
3 answers

Using regex to extract numbers and symbols from string

I have a string with text, numbers, and symbols. I'm trying to extract the numbers, and symbols from the string with limited success. Instead of getting the entire number and symbols, I'm only getting part of it. I will explain my regex below, to…
jessica
  • 1,667
  • 1
  • 17
  • 35
5
votes
2 answers

Regex - PHP Lookaround

I have a string, such as this: $foo = 'Hello __("How are you") I am __("very good thank you")' I know it's a strange string, but stay with me please :P I need a regex expression that will look for the content between __("Look for content here") and…
Flukey
  • 6,445
  • 3
  • 46
  • 71
5
votes
2 answers

Multiple wildcard preg_match_all php

I want to extract a number from html, between .... I have tryed to following code: $views = "/(.*?)<\/td>/"; after -views- is a random number. What is the right code for ignoring the random…
5
votes
3 answers

What does the "~" character signify in PHP regex?

What does the "~" character mean in the following?: preg_match_all("~]+>~", $inputw, $output); My guess is that they are beginning and end markers such as ^ and $.
Theramax
  • 195
  • 1
  • 13
5
votes
4 answers

Get all nested curly braces

It is possible to get all content in nested curly braces from string? For example: The {quick} brown fox {jumps {over the} lazy} dog So i need: quick over the jumps {over the} lazy Better in this sequence, from most nested.
droptheplot
  • 608
  • 6
  • 22
5
votes
2 answers

While fetch html content through "preg_match_all" function special char not display proper, how to resolve this?

I'm fetch the html content using below code, preg_match_all('/
(.*?)<\/div>/s', $str, $matches); echo $matches[1][0]; Content fetched correctly but some special char whit text not display properly like “response to what?”…
Wiram Rathod
  • 1,895
  • 1
  • 19
  • 41
4
votes
3 answers

regex, php, and the evil nested (?R)

UPDATE So I am still messing with this, and have gotten as far as finding all the instances of tags, though I'd rather JUST find the deepest stacked instance, as life would be easier that way.. Anyway here is what I got.. /(({{)(?:(?=([^\/][^…
NinjaKC
  • 821
  • 9
  • 15
4
votes
4 answers

Understanding Pattern in preg_match_all() Function Call

I am trying to understand how preg_match_all() works and when looking at the documentation on the php.net site, I see some examples but am baffled by the strings sent as the pattern parameter. Is there a really thorough, clear explanation out there?…
Kevin_TA
  • 4,575
  • 13
  • 48
  • 77
4
votes
3 answers

Having trouble with this regular expression in PHP

I'm trying to run regular expression on the following string with PHP using preg_match_all function "{{content 1}}{{content 2}}" The result I'm looking for is array with 2 matches inside {{ and }} Here is the expression '/\{\{(.+)\}\}/' I'm…
marcin_koss
  • 5,763
  • 10
  • 46
  • 65
4
votes
3 answers

PHP preg_match_all limit

I'm using preg_match_all for very long pattern. when run the code, i got this error : Warning: preg_match_all(): Compilation failed: regular expression is too large at offset 707830 After searching, I got the solution, so I should increase value…
Ahmad
  • 4,224
  • 8
  • 29
  • 40