# simple regex (not for me)



## vingtage (May 20, 2010)

Hello everybody,
I need to detect if a line contain a word, this word is at the end of the line and it could have or not a slash at the end of the line, there is an example:

```
directory Exemple/Test/
directory Exemple/Test
```

if I want to detect the both lines because there is Test, I use grep:

`grep '.*/Test/?$'`

but it doesn't work.

Can you help me?

(Don't worry if my english is bad, I don't control very well Shakespeare's language)


----------



## crsd (May 20, 2010)

Use [cmd=""]egrep[/cmd] or [cmd=""]grep -E[/cmd] (which is the same).

```
printf "directory Example/Test/\ndirectory Example/Test\ndirectory Example/Test/Not" | egrep '/Test/?$'
directory Example/Test/
directory Example/Test
```


----------



## vingtage (May 20, 2010)

Thank you very much, it works well!


----------



## sixtydoses (May 20, 2010)

Assuming those are lines in a file named testgrep:

`egrep '(Test|Test/)'$ testgrep`


----------

