• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Javascript to check string value and remove if it matches a pattern?

Kevin

Well-known member
#1
Is this doable in javascript?

If I have a string like "James and the Giant Peach (tt0116683)" (without the quotes) I want to see if the string ends with an opening & closing parenthesis and if what is in the parenthesis starts with "tt" then, if it meets that criteria, to remove the content in the parenthesis & the parenthesis characters.

In the example of "James and the Giant Peach (tt0116683)" it'd be see if the string ends with "(tt{value})" and if the condition is true then end up with just "James and the Giant Peach".
 

EQnoble

Well-known member
#3
Is this doable in javascript?

If I have a string like "James and the Giant Peach (tt0116683)" (without the quotes) I want to see if the string ends with an opening & closing parenthesis and if what is in the parenthesis starts with "tt" then, if it meets that criteria, to remove the content in the parenthesis & the parenthesis characters.

In the example of "James and the Giant Peach (tt0116683)" it'd be see if the string ends with "(tt{value})" and if the condition is true then end up with just "James and the Giant Peach".
yes within JS you can get the contents of a set of tags and run a regex match against them and from there you can do whatever you want including updating html to reflect the changes you specified.
 

Kevin

Well-known member
#4
yes within JS you can get the contents of a set of tags and run a regex match against them and from there you can do whatever you want including updating html to reflect the changes you specified.
Happen to know what the regex match would be?