Regex Option Non Capture

Page 1 of 1

1 Replies - 166 Views - Last Post: 21 November 2017 - 06:20 AM Rate Topic: -----

#1 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 270
  • Joined: 10-January 14

Regex Option Non Capture

Posted 21 November 2017 - 06:15 AM

Hello,

Can anyone help me with optional non capture groups in php regex? I had some code from a C# project I was helped with, but can't convert.

$string = ltrim($this->text, '<');
      $string = rtrim($this->text, '>');
      $string = trim($string);
      $matches = array();

preg_match_all(
											'/(?:put|place) (?:the)? (?<subject>.+) in (?:the)? (?<container>.+)/',
											$string,
											$matches,
											PREG_PATTERN_ORDER
							);
							
							var_dump($matches);



I get empty results unless I include "the" in each optional group.

Thanks for any help.

This post has been edited by JeremyBenson11: 21 November 2017 - 06:16 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Regex Option Non Capture

#2 JeremyBenson11   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 270
  • Joined: 10-January 14

Re: Regex Option Non Capture

Posted 21 November 2017 - 06:20 AM

Sorry for double post. This can be deleted. Little problem with slow connection and back page.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1