Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex match last character

I have the following lines,

data:text/javascript;base64,Ly8gSGVyZdsdsd:5
data:text/javascript;base64,Ly8gSGVyZdsdsd:2
data:text/javascript;base64,Ly8gSGVyZdsdsd:1

I want to select the second line of text above using a regex that matches string that ends in 2? I'm stuck, this is what I have:

^.*$
like image 292
Alien Xu Avatar asked Oct 29 '25 02:10

Alien Xu


1 Answers

You can use a very simple pattern

string.match(/.*2$/m)
=> ["data:text/javascript;base64,Ly8gSGVyZdsdsd:2"]

Where m stands for multiline. Without that the $ will be matched at the end of the string, whereas with this it will match end of each line.

like image 151
nu11p01n73R Avatar answered Oct 30 '25 18:10

nu11p01n73R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!