Sunday, 15 May 2011

regex - TCL Expect Using Regular Expressions to Extract String -


I am trying to extract a wire from a file that matches the following format:

The code below ap [1] captures all the data sharing the same line as the string given above. [NABNN 2]. [Second Nabin] [Third NABNEL]

For example: AP30f7.0df6.e51c

What can I do to capture any unwanted data found on the same line as the above string? Am I

  while {$ $ fchan inline]> gt0 = $} {switch -range xp - $ inline {ap ([a-f0- 9] {4} \. [A-f0- 9] {4}. [A-f0- 9] {4}) {default_name $ inline \ n}}}   

Update:

Found a job nearby. Since the condition I defined from each row starts with the desired string, I only use the string category command to extract the first 16 characters.

  {[$ Fchan gets inline]> gt; = 0} {switch -regexp - $ inline {AP ([a-f0- 9] {4} \. [A-f0- 9] {4} \. [A-F0- 9] {4}) {set Inline_mode [string range $ inline 0 15] appleline default_name $ inline_mode \ n}}}    

When you want to extract as an RE matching at the same time, then there are some useful options in the switch command, especially, you should use.

  while {$ $ fchan gets inline> gt = 0} {switch - ray xp- match match - $ inline {ap ([a-f0-9] {4} \ . [A-f0- 9] {4}. [A-f0- 9] {4}) {# Remove the first and second elements $ matched inline_mod triple # ap 30f7.0df6 with your sample .e51c # $ Inline_mod "AP30f7.0df6.e51c" # $ is triple "30f7.0df6.e51c" Add default_name $ inline_mod \ n}}}   

Here are some more examples of manual pages.

No comments:

Post a Comment