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

Kevin

Well-known member
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".
 
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.
 
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?
 
Luke, excellent, thank you! One quick question... is it possible to make the length any value that meets the match instead of explicit 7?

Code:
"James and the Giant Peach (tt0116683)".replace(/( ?\(tt\d+\))$/, "")
 
Back
Top Bottom