Questions tagged [pcre]

Perl compatible regular expressions syntax and library

PCREs refers to an extended regular expression syntax and the corresponding free and open source regex matching library that implements it as used by pcregrep, grep -P and a plethora of utilities and programming languages (zsh, wget, snort, php...).

It closely emulates perl 5 regular expressions with a few extensions of its own.

Use this tag for questions related to the syntax of those regular expressions or questions related to using the PCRE library.

28 questions
9
votes
2 answers

Does GNU grep's -o option ignore zero-length matches?

I found an answer on another site that was suggesting grep -oP '^\w+|$. I pointed out that the |$ is pointless in PCRE, since it just means "OR end of line" and will therefore always be true for regular lines. However, I can't exactly figure out…
terdon
  • 234,489
  • 66
  • 447
  • 667
8
votes
1 answer

PCRE-regex Use grep to exclude a capturing group

I am using GNU grep with the -P PCRE Regex support for matching strings from a file. The input file has lines containing strings like: FOO_1BAR.zoo.2.someString:More-RandomString (string here too): 0.45654343 I want to capture the numbers 2 and…
Inian
  • 12,472
  • 1
  • 35
  • 52
7
votes
1 answer

How to refer to matched groups in jq gsub?

Using jq, I want to search for a pattern via regex, and wrap the matched string with something like
tags $ echo "\"This is a valid json file"\" | jq '. | gsub("valid";"how_to_refer_to_matches";"i") - How to refer to the matched results in the…
Zeta.Investigator
  • 880
  • 1
  • 7
  • 25
6
votes
5 answers

Local installation of pcre2 not detected while installing R 4.0.4 from source

I am trying to do a build and local install of R 4.0.4 on Red Hat Linux 6.8. There were several unmet dependencies which I resolved by doing local installations (following the procedure in this). However, I couldn't resolve the issue of pcre2 with…
Dronacharya
  • 161
  • 1
  • 2
3
votes
0 answers

In journalctl internal grep, is it possible to specify option to only output matched pattern?

I have the following journal messages: $ journalctl _COMM=kwin_wayland -o cat --since "-10s" ... kwin_screencast: Dropping a screencast frame because the compositor is slow kwin_screencast: Dropping a screencast frame because the compositor is…
Ashark
  • 767
  • 7
  • 24
3
votes
2 answers

Rename file with the rename tool - moving around square brackets

Rookie question. Following this answer Move last part of filename to front, I'm trying to do the same, except all files in my case contains square brackets. What I want is to move the title to the other side of the brackets (keeping the file…
Nicolas Ø
  • 45
  • 2
3
votes
3 answers

Extract text starting at specific category header to next category header from a text file

I have a TOML file in the following format (categories may have any name, the sequential numbering is just an example and not guaranteed): [CATEGORY_1] A=1 B=2 [CATEGORY_2] C=3 D=4 E=5 ... [CATEGORY_N] Z=26 What I want to achieve is to retrieve…
Educorreia
  • 165
  • 7
3
votes
1 answer

Postfix PCRE maps broken in RHEL8: "error: unsupported dictionary type: pcre"

My Postfix config worked flawlessly in RHEL 7 and now all maps which rely on PCRE in RHEL are busted after migrating the config to RHEL 8. postfix/cleanup[xxxx]: error: unsupported dictionary type: pcre Is PCRE support deprecated in Postfix in RHEL…
F1Linux
  • 2,286
  • 1
  • 16
  • 28
3
votes
1 answer

swig error in ubuntu 16.04

For some reason swig on my computer is not configured correctly. It gives this output on checking version: $ swig --version swig: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or…
Piyush Verma
  • 31
  • 1
  • 4
2
votes
5 answers

Matching Repeating Pattern Using Regex

Let's say I have a file like following 1,2,3-5,6 1,2,3-5,6, 1 1-3 1,2,3-,4,5-7 1,2,3-,4,5-7, 1,2,-3,4,5 1,2,-,3,4 1,2,,,3,4 ,1,2,3 Only combination of following rules should be considered as valid: Ranges [0-9]+-[0-9]+ Groups [0-9]+,[0-9]+ Single…
GypsyCosmonaut
  • 3,988
  • 7
  • 38
  • 62
2
votes
5 answers

How can I extract strings from one file to insert (modified) in a different file?

problem is the following: I have an xml file with data and I am looking for a small part of the data to write it into a new file: content has been shortened by request: snippet if type=dhcp-client:
Questi
  • 45
  • 8
1
vote
4 answers

Find lines with first word containing a certain set of letters

The input file exists out of lines containing multiple 10-letter combinations: NGNAEAREAX EAHVSELYCI FNWGNLACQM AWKLRMDHIT PRYMFNYMVM NCNREDEEEQ EAHVSELYCI FNWGNLACQM AWKLRMDHIT PRYMFNYMVM I need a regex (PCRE or BRE/ERE) that finds all lines of…
Tomyy
  • 155
  • 6
1
vote
1 answer

Can I change the regex engine used to search in `less`?

I would like to use a perl compatible regex engine in the less command line utility. Is that possible?
drevicko
  • 313
  • 2
  • 9
1
vote
2 answers

Advanced regex: Can't figure a case where (?R) recursive regex can be used

Is anyone here can explain a case where the recursive Perl/PCRE regex (?R) can be helpful ? I…
1
2