Jump to content

[SOLVED] tricky regex?


DamienRoche

Recommended Posts

Here's what I want to do with this.

 

match everything between > and < -

 

1. can have space from beginning or end but cannot be a space and cannot be nothing (i.e. >< or > <) -

 

2. must be either a number or a word - number cannot end with .

 

Here's my current regex with example string:

 

<?php

$str = ">< > < >123.< > 999 < >8,88< >eight< > eig.ht < >ni.ne< > nine <";

preg_match_all('#>.+?<#is', $str, $matches);

print_r($matches);

?>

 

desired output:

 

Array ( [0] => Array ( [0] => > 999 < [1] => >8,88< [2] => >eight< [3] => > eig.ht < [4] => >ni.ne< [5] => > nine < ) )

 

I've had a bash but I can't figure it out. Would love your advice on it. Thanks.

 

Any ideas are welcome.

 

 

Link to comment
https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/
Share on other sites

Hi, I've run into a little hiccup with this regex.

 

it ignores anything that is in this format:

 

123.onetwothree

 

it doesn't allow the number and the period in the same string.

 

Is there a way to say only exclude those with . at the end?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/128389-solved-tricky-regex/#findComment-665510
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.