Regex to hunt for a string in the right hand column

I have a database which has the following structure

English word=IPA notation

as in the example below

huckleberry=hkl-bri
huddling=hd-l
huffish=h-f
hugger-mugger=hgr-mgr
hulling=h-l
human=hju-mn
humanitarian=hju-m�nteryn
humanitarianism=hju-m�nternzm
humanitarians=hju-m�nterynz
humbler=hmb-lr
humblest=hmb-lest
humbling=hmb-l
humid=hju-md
humming-top=hm-tp
humming-tops=hm-tps
humourless=hjumr-l�s
hunchback=hn-b�k
hunchbacks=hn-b�ks
hundredfold=hndred-fold
hunger-march=hr-mr
hunger-marcher=hr-mrr
hunger-marchers=hr-mrrz

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

humourless=hjumr-l�s
hunchback=hn-b�k
hunchbacks=hn-b�ks
hundredfold=hndred-fold

I work under windows but a Perl or even Unix regex could help. Many thanks

With your sample data contained in a file named database.txt , any of the following commands:

grep '^[^-]*=.*-' database.txt
awk '/^[^-]*=.*-' database.txt
sed -n '/^[^-]*=.*-/p' database.txt

produce the output:

huckleberry=hkl-bri
huddling=hd-l
huffish=h-f
hulling=h-l
human=hju-mn
humanitarian=hju-m�nteryn
humanitarianism=hju-m�nternzm
humanitarians=hju-m�nterynz
humbler=hmb-lr
humblest=hmb-lest
humbling=hmb-l
humid=hju-md
humourless=hjumr-l�s
hunchback=hn-b�k
hunchbacks=hn-b�ks
hundredfold=hndred-fold

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

Please, try the following:

perl -ne '/^\w+=.+-/ and print'

Or test with any regex engine that suport Perl regex.

/^\w+=.+-/

Many thanks. The second syntax

/^\w+=.+-/

worked just fine.

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:

a-bomb=ebm
a-bombs=ebmz
a-level=elevl
a-levels=elevlz

I tried the regex

.+-/=^\w+

but it failed and did not detect anything. Why did this fail?
What modification is needed? Thanks a lot for satisfying my curiosity.

A couple of things to note first:

(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:

^.+-\w+=\w+$

And it should work with your data:

$
$ echo "a-levels=eilevelz" | perl -lne 'if (/^.+-\w+=\w+$/){print "matched"} else {print "unmatched"}'
matched
$
$ echo "alevels=ei-levelz" | perl -lne 'if (/^.+-\w+=\w+$/){print "matched"} else {print "unmatched"}'
unmatched
$
$ echo "a-levels=ei-levelz" | perl -lne 'if (/^.+-\w+=\w+$/){print "matched"} else {print "unmatched"}'
unmatched
$
$ echo "alevels=eilevelz" | perl -lne 'if (/^.+-\w+=\w+$/){print "matched"} else {print "unmatched"}'
unmatched
$
$
 

You could, alternatively use the regex

/^\w+-\w+=\w+$/

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 .