PDA

View Full Version : [all variants] regex brackets



SpinningAround
July 4th, 2010, 06:36 PM
Is it possible to match a expression that look somethin like this.

maybe somethin[something]maybe something

DaithiF
July 4th, 2010, 10:14 PM
sure. not sure whether you are just searching for matching items, or wanting to do a search/replace, but heres a search/replace example:

$ cat testfile
text at beginning maybe somethin[something]maybe something text at end
text at beginning [something] text at end

$ sed 's/\(maybe somethin\)\?\[something]\(maybe something\)\?/REPLACED/' testfi
le
text at beginning REPLACED text at end
text at beginning REPLACED text at end