March 19th, 2013, 06:07 PM
Need to find value after 3 dashes
find SS and BCP from following string
what I want to do is find the value after third "-" which is
PMR in first string and BCP in second string
any help will be highly appreciated
March 19th, 2013, 07:22 PM
If the string contains an indeterminate number of sections and you always want to match the fourth one from the beginning, then it's better to write your regular expression so that it matches from the beginning of the string rather than the end.
If you can extract a subgroup from the match, then write an expression which matches the first four sections as separate subgroups and pull out the 4th one.
If you can't extract a subgroup, check to see whether the regular expression engine that you're using supports zero-width look-behinds.
March 20th, 2013, 06:25 PM
An easy solution in Perl:
my $c = "ANG-B31-OPS-PMR-MACE-SS-0229"
my ($d, $e) = (split /-/, $c) [3,-2];
print "$d, $e"; # prints PMR, SS
It will be slightly different in other languages, perhaps very slightly more complicated than just one short line of code as above, but your language is likely to have a split function that will be the basis of a similar solution.
March 29th, 2013, 07:34 PM
This is one to do it in a shell script:
$ cat search_example.sh
oIFS=$IFS ## Save current setting
while read -a Arr theFile
done < t
$ cat t