Created
September 7, 2011 20:17
-
-
Save ThomasBurleson/1201605 to your computer and use it in GitHub Desktop.
AS3 complex string replacements with Regular Expressions (RegExp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Use regular expressions to easily replace tokens within specific patterns | |
| * Here we are using SWFAddress with deep linking to update the browser fragment | |
| */ | |
| var url1 : String = "http://www.test.com/ria.html#/user/100083?view=13432&filter=all&layout=horizontal" | |
| var url2 : String = "http://www.test.com/ria.html#/user/100083&filter=all/edit" | |
| // Here we want to update [with filter value above] only the section filter=xxx; | |
| // without affecting any other part of the fragment... | |
| var pattern : RegExp = /filter=(user|critical|all)/gi; | |
| // Current filter value | |
| var filter : String = "user" | |
| trace ( url1.replace( pattern, supplant("filter={0}",[filter] ) ) ) | |
| trace ( url2.replace( pattern, supplant("filter={0}",[filter] ) ) ) | |
| // output url1 == `http://www.test.com/ria.html#/user/100083?view=13432&filter=user&layout=horizontal` | |
| // output url1 == `http://www.test.com/ria.html#/user/100083&filter=user/edit` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment