Hi,
I have a little smarty question, hopefully someone can help me out : )
I have many strings that follow the following scheme :
Espiritu Santo, Vanuatu (SON)
Hamilton Island, Australia (HTI)
Bangkok, Thailand (BKK)
New York, NY, United States (NYC)
...
If {$mystring} is Bangkok, Thailand (BKK) how do I make the output to show :
BKK ?
If {$mystring} is New York, NY, United States (NYC) how do I make the output to show :
NYC?
... ,etc
I hope it's not too confusing :)
Thanks
smarty regex_replace [SOLVED]
smarty regex_replace [SOLVED]
Last edited by antosha on Sun Feb 28, 2010 9:56 pm, edited 1 time in total.
Re: smarty regex_replace
Have you tried substr?
{$mystring|substr:-4:3}
Nullig
{$mystring|substr:-4:3}
Nullig
Re: smarty regex_replace
Code: Select all
{assign var='test' value='New York, NY, United States (NYC)'}
{$test|regex_replace:'/^.*\(|\)/':''}
http://www.regular-expressions.info/jav ... ample.html
http://www.regular-expressions.info/reference.html
Re: smarty regex_replace
Thanks a lot, both solutions work great 
@ Nulling: I didn't know "substring" modifier existed in smarty, thanks.
@ Peciura: thanks for regex documentation, that will help me a lot.

@ Nulling: I didn't know "substring" modifier existed in smarty, thanks.
@ Peciura: thanks for regex documentation, that will help me a lot.