Questions tagged as ['regex']

Regex (or regexp) is known as regular expression matching of patterns, strings or characters in, for example, a large text file. Questions should be tagged as such whatever the programming language involved and the tag can also apply to command-line or graphical programs that have regex plugins or some regex capability.
Score: 1
tscizzle avatar
In arbitrary line of text, how can bash extract a named value after an equal sign?
ao flag

This question (How to get values after an equal sign) is basically what I want:

Given a line of text, with named parameter looking syntax like color=red, using bash how can you grab that color value (yielding red)?

Except in that question, the line of text is entirely those key-value pairs, so the accepted answer utilizes bash's eval since that syntax happens fit very nicely.

I'm wondering for a gen ...

Score: -1
CryptoTrader avatar
match all the items that i have enough of to afford. simple regex
in flag

Taking a self guided linux tutorial and I keep getting hung up on this

My output keeps including the "clock 15" please help

#comment single RegEx to match all of the items that you have enough rupees 
sed '1d' hw0207.txt | grep -v [2-9][0-9]
#comment grep will filter all numbers greater than 12, -v represents not
#comment first sed was to remove first line

regex to match directions

I'm ...

Score: 0
Rinke avatar
LibreOffice: indent all lines starting with italic via find/replace
in flag

I have a huge text, and I would like to indent all lines which start with italic text, via find/replace.

I tried using ^ and italic via the format button, but then the search string is not found.

If I fill in ^. and italic (via the format button), then due to the dot it finds the search strings, but then my first letter is disappearing everywhere when I enter \t in the replace box.

So how to deal with  ...

Score: 0
CryptoTrader avatar
Regex to match lines that access a certain port and particular packets
in flag

New to Linux and the only way I can get this to work is by using the awk command unfortunately the main directions specify to not use awk.

this is what I got

#comment Write a single RegEx to match the lines that access port 22 and only those packets
grep '\s22\s' hw0206.txt | awk {'print $4'}
#comment grep returns the whole line with matched string
#comment \s22\s regular expression to match ...
Score: 0
Pedro Miguel Silva avatar
Rename using both captured groups and other variables
ws flag

In this question I understood that we can only refer to captured groups in the rename command using single quotes.

Is there a way to use both captured groups and other variables in the same rename command?


cd /etc
rename 's/(bash\.bashrc)/$1$var/' *
Score: 0
Cas avatar
when using ?!<string> in perl regex, bash interprets it as search through command history
in flag

Simple problem but I can't fix it.

I have the following perl regex:

echo ... | grep -P "(?i)(v(ersion)?)\s?(?!0)\d(\.|,)\d{1,}"

This is supposed to match every string that describes a version of something (e.g. V2,0 or version 1.2). But it doesn't match when the version starts with V0.... However, when I execute this, I get an error -bash: !0: event not found because !<string> is used to search thr ...

Score: 0
Cas avatar
When piping grep after a curl request, regex works very strange
in flag

Simple problem but really weird.

When I make a curl request and do ... | grep -Po "^\d+$", it returns nothing eventhough there are 400+ results that should match. See below:

#example snippet of curl output
00:15:54,936 --> 00:15:56,646
Yeah, this is him.
We got him.

00:16:07,823 --> 00:16:11,869
So, how long
you been in South Florida?

00:16:11,953 --> 00:16:13,871
A while.
Be ...