Jump to content

Regex PHP newline?

Go to solution Solved by Mr_KoKa,

It is because you have <\/tr> at the end of your regexp, but it is nowhere in your html you pasted.

Hello, I'm trying to match this line.

 

ZMan will change, 6,500,000 will change and the date.

<td style="height: 30px; text-align: left;"><b>ZMan</b> wired <b>6,500,000</b> Dollar.</td>
<td>28-03-2017 21:10:00</td>

 

This is what I use now and it doesent work.

 

<b>(.*?)<\/b> wired <b>((\d*|\,*)*)<\/b> Dollar.<\/td><td>(\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2})<\/td><\/tr>

So how can I detect the newline?

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/
Share on other sites

Link to post
Share on other sites

Try

<b>(.*?)<\/b> wired <b>((\d*|\,*)*)<\/b> Dollar.<\/td>\s+?<td>(\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2})<\/td><\/tr>

\s means white space character so \r\n\t\f\v and space, * will match any amount or none and ? at the end will make it lazy not sure if needed, I am also not sure that last </tr> as you didn't mention it in your html, but I guess you put it there for a reason.

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/#findComment-9592049
Share on other sites

Link to post
Share on other sites

2 minutes ago, Mr_KoKa said:

Try


<b>(.*?)<\/b> wired <b>((\d*|\,*)*)<\/b> Dollar.<\/td>\s+?<td>(\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2})<\/td><\/tr>

\s means white space character so \r\n\t\f\v and space, * will match any amount or none and ? at the end will make it lazy not sure if needed, I am also not sure that last </tr> as you didn't mention it in your html, but I guess you put it there for a reason.

Both, regex101.com and regexr.com says it still doesent match :(

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/#findComment-9592075
Share on other sites

Link to post
Share on other sites

Just now, Mr_KoKa said:

It is because you have <\/tr> at the end of your regexp, but it is nowhere in your html you pasted.

Removing the \ just makes it says pattern error, I figured out that if the content got / you need to use \ infront of it to make it count it as content

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/#findComment-9592093
Share on other sites

Link to post
Share on other sites

I mean <\/tr> as a whole, you won't match </tr> if there is no </tr>

For this html:

<td style="height: 30px; text-align: left;"><b>ZMan</b> wired <b>6,500,000</b> Dollar.</td>
<td>28-03-2017 21:10:00</td>

This will match:

<b>(.*?)<\/b> wired <b>((\d*|\,*)*)<\/b> Dollar.<\/td>\s+?<td>(\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2})<\/td>

And those will be captured:

ZMan

6,500,000

28-03-2017 21:10:00

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/#findComment-9592107
Share on other sites

Link to post
Share on other sites

1 minute ago, Mr_KoKa said:

I mean <\/tr> as a whole, you won't match </tr> if there is no </tr>

For this html:


<td style="height: 30px; text-align: left;"><b>ZMan</b> wired <b>6,500,000</b> Dollar.</td>
<td>28-03-2017 21:10:00</td>

This will match:


<b>(.*?)<\/b> wired <b>((\d*|\,*)*)<\/b> Dollar.<\/td>\s+?<td>(\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2})<\/td>

And those will be captured:

ZMan

6,500,000

28-03-2017 21:10:00

Oooooh, Did not see that, thanks!

and yes it works now :D

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/#findComment-9592126
Share on other sites

Link to post
Share on other sites

I have optimize capturing that number of dollars

<b>(.*?)<\/b> wired <b>([\d\,]*)<\/b> Dollar.<\/td>\s+?<td>\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}<\/td>

Instead of ((\d*|\,*)*) it is now ([\d\,]*)

Square brackets creates characters group, and then * makes match for from zero to unlimited occurrence of character from that group.

Link to comment
https://linustechtips.com/topic/758948-regex-php-newline/#findComment-9592169
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×