I want to identify all instances of a hyphen in the right-hand column i.e. IPA and which are missing in the left-hand column i.e. the English Words. A small example is given below
As always, without knowing what utility will be using a regular expression, we don't know the type of regular expression nor how that RE will need to be delimited to get the results you want.
Thanks a lot for your kind help. I am sorry I should have been more explicit.
I use Ultraedit which allows for regexes both under PERl and UNIX environments
Basically I want to plug in the regex in the editor and write a macro which will remove all such unwanted hyphens.
The regexes you provided work with Grep or Awk but when I plug them into the editor as Unix regexes, they do not identify correctly although the syntax seems correct.
Do not find a hyphen in column one but find in column 2
Thanks once again for your help
I am carrying the query a bit further as a matter of curiosity. The regex string in Perl
^\w+=.+-
checks for a hyphen on the right hand side of the database delimited by an
=
sign
whereas no hyphen exists in the left hand side.
Out of curiosity I reversed the regex as under to find all instances in the database where a hyphen exists in the left hand side but not in the right hand side as in the examples below:
(1) The "/" before the "=" is usually incorrect. By default, Perl uses forward-slashes as "pattern terminators" to match a pattern, like so:
if (/abc/) { <do-something> }
So a forward-slash inside the pattern will not work by default.
You could make it work, however, if you use non-default pattern terminators with the "m" (match) operator, like so:
if (m|abc/def|) { <do-something> }
Many other pattern terminators and even "pairs" are allowed: "", "{}", "()", "!!" etc.
(2) Note that the forward-slash was not present inside the pattern in the original solution. So, if your intention was to escape the "=", then the correct character is the back-slash "\". And even then, the "=" does not need to be escaped in Perl. It does not hold any special meaning.
So, now the regex is reduced to:
.+-=^\w+
(3) Next, notice the caret ("^"). It is a start-of-line anchor. It does not match any character. It matches a position: the "start of pattern". Hence it is always used at the start of the pattern. If you use it within the pattern, it will not match anything.
So, now the regex is reduced to:
^.+-=\w+
(4) Now if you take a step back and look at the original regex:
/^\w+=.+-/
/ => left pattern terminator
^ => beginning of pattern
\w+ => a word (by definition, a "word" does not have hyphens in Perl)
= => followed by the "=" character
.+ => 1 or more occurrences of any character
- => followed by a hyphen character
/ => right pattern terminator
In the original regex, we stop the moment we reach a "-" on the right hand side. We found what we wanted, so we take the relevant action.
But when you switch the patterns around the "=" character, that may not be true. So you put something after the "-" character on the left hand side, like so:
^.+-\w+=\w+
(5) Finally, you want to ensure that the word on the right hand side does not have any hyphens. The regex above matches a "word" on the right hand side, but if that "word" is followed by a hypen, it will still match it.
To ensure that you have a word without any hyphens on the right hand side till the end of the string, you put a "end of pattern" anchor: "$".
It is the counterpart of the "start of pattern" anchor: "^".
So now the regex becomes:
Sorry for the delay in responding. Many thanks for the detailed and instructive "tutorial.". The comments helped me understand what went wrong and what I should do in the future .