pcregrep searches files for character patterns, in the same way as other grep commands do, but it uses the PCRE regular expression library to support patterns that are compatible with the regular expressions of Perl 5.
Questions tagged [pcregrep]
76 questions
0
votes
2 answers
how to trim the absolute directory path?
I have a absolute path to directory halo:
/pkg/check/power/halo
I want to trim the absolute path to only:
/pkg/halo
how can i do that using regex or pcreCompile function or unix?

Surabh S
- 11
- 4
0
votes
0 answers
What is the difference in PCRE pattern: `(?!or|and)\w+` and `[(?!or|and)\w]+`?
What I want to capture is some variable/call expressions without or or and keywords.
As the title says, what is the difference between (?!or|and)\w+ and [(?!or|and)\w]+ ?
I'm sure those are different, because for the following pattern:
...
if…

sangwoo-joh
- 127
- 6
0
votes
1 answer
Pcregrep duplicating matching multi-line patterns?
I have a text file which contains 2 lines of a sample DNA sequence, usingpcregrep, I want to find patterns matching "CCC" especially the patterns that span through multiple lines (see end of line 1 to the beginning of line 2 in test.txt below)…
0
votes
3 answers
Multiline grep with specific text
There is an xml file with lot of -s in it.
I need to see those A tags (and their children, so the tags' whole content) that have at least one .
So this block should match (therefore contained in the result):
...
...
…

Törpetestű
- 192
- 10
0
votes
1 answer
Bash: how to certain lines but exclude certain lines in between?
I have a file that looks like this:
a: 0
a: 0
a: 0
a: 1
b: 1
c: 1
d: 1
e: 1
f: 1
a: 2
b: 2
c: 2
d: 2
e: 2
f: 2
a: 3
b: 3
c: 3
d: 3
e: 3
f: 3
c: 4
c: 4
c: 4
I want to capture and output all of the a and c lines of the form

gkeenley
- 6,088
- 8
- 54
- 129
0
votes
0 answers
How can I search for substrings in plain text files using libpcre2?
I want to use libpcre2 to match substrings in plain text files, but libpcre2 does not provide: pcre2_match_file() or pcre2_match_fd() API. It seems that I need to open the file myself and take each line and pass it to the pcre2_match() function in…

chenzhongxiang
- 1
- 2
0
votes
1 answer
Using pcregrep with --color option - only highlight non captured expression?
I would like to use pcregrep with its --color option to highlight text that follows a particular pattern:
e.g. if file.txt contains:
bob says hi
chloe says hello
then running:
pcregrep --color '(?:says)(.*)' file.txt
prints
bob says hi
chloe says…

user1279887
- 489
- 4
- 20
0
votes
0 answers
How to match something n times or less with pcregrep?
The following command will highlight 4 a's instead of 3 a's. I just want to match for no more than 3 a's. Is there anything wrong with the regex that I use?
pcregrep --color 'a{0,3}' <<< aaaabbb

user1424739
- 11,937
- 17
- 63
- 152
0
votes
1 answer
split pcregrep multiline matches
tl;dr: How can I split each multiline match with pcregrep?
long version: I have files where some lines start with a (lowercase) character and some start with a number or a special character. If I have at least two lines next to each other starting…

Jyy
- 3
- 1
0
votes
0 answers
MySQL CASE statement with REGEXP not working
I want to use a CASE statement that uses REGEXP. Currently I am doing something like this:
SELECT `date_of_sale`,
CASE
WHEN `date_of_sale` regexp '[0-9]*-[0-9]*-[0-9]*' then str_to_date(`date_of_sale`, '%m-%d-%Y')
ELSE
`date_of_sale`
…

Divyarajsinh
- 188
- 3
- 9
0
votes
2 answers
pcregrep in bash function not working properly
I'm doing an script that check configuration files. In order to check multiple lines at once I'm using pcregrep. When i use it in command line everything works great.
When I put it inside a function it does not fidn the pattern.
This is my…

Abel
- 151
- 4
0
votes
1 answer
Find file that match patterns located in different lines
I'm doing a program that can find a file(s) that match two patterns given by the user (Date and ID), both patterns are located in different lines inside every file. The files are located in different .zip sub folders. My code is not working and I'm…

Jafet Soto
- 41
- 6
0
votes
1 answer
Pcregrep include file extension bug
I'm using pcregrep to search for a multiline pattern, and I only want pcregrep to search through files with specific file extensions, i.e.
pcregrep -Mrl --include=*.sv -e '' /path/to/search
However, this throws an error:…

mgoblue92
- 57
- 6
0
votes
2 answers
Python: Make List of Matching Patterns for Subprocess Call to pcregrep multiline
TLDR: Is there a clean way to make a list of entries for subprocess.check_output('pcregrep', '-M', '-e', pattern, file)?
I'm using python's subprocess.check_output() to call pcregrep -M. Normally I would separate results by calling splitlines() but…

mgoblue92
- 57
- 6
0
votes
3 answers
Get inside of parent blocks in php regex
hello i have 2 parent (or more ...) block and many child blocks inside them.
Block1 {
blockchild1 {
}
blockchild2 {
}
, ...
}
Block2 {
blockchild1 {
}
blockchild2 {
}
, ...
}
i want to use php…

Elh48
- 43
- 8