Surface Engineering Forum

  • Alternative Forum Home PageSEF Portal
  • Old S E Message Board ArchivesOld Message Board Archives
  • Search
  • Member List
  • Calendar
  • Help

Current time: 02-18-2019, 11:11 AM Hello There, Guest! (Login — Register)


Surface Engineering Forum / General Discussion / Other Topics v
« Previous 1 2 3 4 5 6 Next »
/ Replace Options in Regular Expression




Post Reply 
Threaded Mode | Linear Mode
Replace Options in Regular Expression
11-09-2012, 08:36 AM
Post: #1
CarlowOlson Offline
Junior Member
**
Posts: 2
Joined: Nov 2012
Reputation: 0
Replace Options in Regular Expression
Hello Friends,

Replacing options in a regular expression can get complicated quickly; you need to isolate the option you want to replace before making any changes. Doing so otherwise will potentially break the rest of the matches. This is why it's a good idea to segregate the different sections of your regular expression using parentheses as it makes it easier to work with individual segments. Regular expressions are used by a variety of scripting languages and are a powerful way to parse data from one or many files.

1. Open the script whose regular expression you would like to edit. Navigate to it.

2. Save a copy of the regular expression before changing anything by copying and pasting it into another file. Now find the parts of the regular expression you wish to change. So for example, you have:
([0-9]+[a-z])
This part of the expression will match one or more numbers, followed by one letter. If you wanted to replace that part of the expression, simply make your changes within the parentheses, otherwise you will start affecting the rest of the expression.

3. Use the built-in numbered variables to test the matches of your new expression. For each set of parentheses you have, the result of the match is stored in a numbered variable. For example, your expression is:
([0-9]+[a-z])
The sequence in which that appears in your expression is the number it's stored in. If it's the first set of parentheses, then you can see the result by using: print $1; This will print the text that matched your regular expression. If it was the second set of parentheses, you would use "$2" and so on. Continue testing your expression until it does exactly what you need it to do.

Thanks and Regards
Carlow Olson
Send this user an email Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 




Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to Replace the Boot on a Front Load Frigidaire Washer cicididi 2 3,297 04-04-2012
11:09 AM
Last Post: Alexandro8100

  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread


User(s) browsing this thread: 1 Guest(s)





Surface Engineering Forum Sponsor - Alphatek Hyperformance Coatings Ltd

    Subscribe in a reader

    Contact Us | Thermal Spray Coatings | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication

Powered By MyBB, © 2002-2019 MyBB Group.


© Copyright Gordon England