Questions tagged [pcre]
Perl Compatible Regular Expressions(PCRE) was initially developed as a regex engine for PERL, but grew into a library that many other languages (like PHP and Apache) use for their regex. Use with the [regex] tag and any appropriate language tags.
2,324
questions
-1
votes
0
answers
35
views
Grep Regex Rsa Private Key [duplicate]
The idea it to use Grep PCRE regex to find a RSA private key.
The version of Grep being used is:
grep (GNU grep) 2.20
The regex used and not working is:
grep -P "((-----BEGIN RSA PRIVATE KEY-----)...
0
votes
5
answers
125
views
Is it possible to replace characters only within selected a group?
Consider: word1.word2.worda-wordb-wordc.ext
Is there a regular expression capture and replace string that can be used to obtain as result: worda wordb wordc using perl compatible regular expressions?
...
-1
votes
0
answers
16
views
How to convert PCRE2 regex to compatible JavaScript regex [duplicate]
The regex that works with PCRE2 is the following:
<svg(?:\s+viewBox="(?<viewBox>[^"]+)"|\s+width="(?<width>[^"]+)"|\s+height="(?<height>[^"]...
0
votes
1
answer
50
views
Regex PCRE2 verify range of ip address
Currently I'm working on a regular expression wrote in PCRE2 to check a range of IP address
^(10\.).+|(172\.16).+|(192\.168).+
I need the regular expression to check also if in the string I can find ...
1
vote
1
answer
32
views
Griddb Missing Files on PHP Client on Centos 7
I have attempted several times to install the PHP client for Griddb. I used both the manual source and package via Composer. When I try to compile the client, I get header files php.h, and ...
0
votes
1
answer
32
views
Surround input text with slash or backslash
I am trying to surround input string with either \ or /. The input string can only take one of the following forms. The first one is an empty string.
path
/path
\path
path/
path\
/path/
\path\
I am ...
1
vote
1
answer
51
views
Regex to match multiple cases
I have the following examples that must match with my regex
1,[]
1,[0,0,0,[]]
1,[0,0,0,0,0,[]]
1,1
1
I came up with a simple way of matching the middle ones with .?,\[.*\[\]\] but it doesnt match the ...
-2
votes
1
answer
42
views
How would I rewrite PCRE regular expressions so that they're compatible with JavaScript?
As part of a security related project written in Node.js, I'm looking at some of the work done by the team behind PHPIDS, specifically their filter list, which is composed of a large amount of regular ...
2
votes
2
answers
91
views
Improving the performance of an PCRE Regex Pattern
I have the below regex here which is written to support the PRCE/PRCE2 format. However, this throws the following error “Evaluation takes too long. Please check your regular expression.” Is there any ...
1
vote
2
answers
58
views
Regex expression to exclude a string between two capture groups
I am trying to capture the user name and channel id of that user from an api string using regex.
Unfortunately I can not use a JSON Parser on the JSON format so I (beginner) am stuck with Regex.
My ...
1
vote
1
answer
81
views
Writing ECMAScript Javascript Regex to Perl flavour (PCRE) / (PCRE2)
I'm having the below Regex which is written to support the ECMAScript Javascript flavour. However, this has to be re-written in the Perl flavour (PCRE) / (PCRE2)
(?<!x)(?<!\border\D*\W*)(?<!\...
0
votes
1
answer
37
views
Regex does not work on nearly identical raw data in Splunk
Im using Splunk (data monitoring) and I have a regex that checks our logs and needs to return some info of a job failure. The regex works pretty good but for one job failure it does not output ...
0
votes
1
answer
115
views
Regex not matching all numbers with delimiters
Need a single combined regex for the following pattern:
Prefix: 2221-2720 , Length: 16
Prefix: 51-55 , Length: 16
where the delimiters b/w digits can be either space ( ), minus sign (-), period (.), ...
2
votes
2
answers
56
views
regex - multiple matches after a specific word
Simplified example: consider the string aabaabaabaabaacbaabaabaabaa
I want to match all aa occurrences only after the c in the middle, using one regex expression.
The closest I've come to is c.*\Kaa ...
0
votes
0
answers
32
views
Can PCREs match all context-sensitive languages?
It recently came to my attention that most programming languages' regex engines are not faithful implementations of regular expressions in the formal language theory sense. Features like lookahead and ...
-1
votes
2
answers
120
views
How to compile git with PCRE on Mac?
I need the PCRE for this command - git log -i -P --all --grep='^(?=.*fix)(?=.*a)(?=.*bug)'
It shows - fatal: cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE
I tried -
brew ...
2
votes
4
answers
101
views
Replace N spaces at the beginning of a line with N characters
I am looking for a regex substitution to transform N white spaces at the beginning of a line to N . So this text:
list:
- first
should become:
list:
- first
I have ...
1
vote
1
answer
53
views
Regex two separate nested capturing groups
I have a regex and test case on
https://regex101.com/r/5Z5Lop/1
^(?<KEY>CONF|ESD|TRACKING)[:;'\s]\s*(?<DATA>.*?)\s*(?:L[:;'\s]\s*\K(?<LINE_DATA>.*?))?(?<INITIALS>\*[a-zA-Z]+)?\...
2
votes
2
answers
66
views
Do a Nim regex modifier just like Perl one
How is Nim regex PCRE modifier done as in Perl itself is e.g.
/foobar/i
/ foo bar /x
/foobar.*/s
etc ?
Please explain correctly doing such on Nim
Thanks much in advance
-2
votes
2
answers
140
views
More elegant (shorter) solution for this regex pattern
I have spent three days banging my head on how to find a single solution to match anything between either single or double quotes with escaped single or doublequotes within actual source string and to ...
1
vote
1
answer
25
views
Unexpected regex results with polytonic Greek capitals
I am trying to select only capital letters in polytonic Greek text using regex. The specific application is PHP, but I had trouble with it so I started playing around with it in RegExr:
https://regexr....
0
votes
1
answer
117
views
REGEXP_SUBSTR to extract a substring from Vertical SQL
I am trying to run the below query to get a substring from a string but it gives wrong result. I am not sure how to use the regex since the regex I am using works well with PCRE.
SELECT REGEXP_SUBSTR(
...
1
vote
2
answers
47
views
Regex ensure that there's only one blank line(2 newlines) after each section ends and another section begins in any Text-INI file
As I have mentioned in Question title, I have following INI file, which contains umpteen number of sections and each section containing umpteen lines:
....
.... (many more section up above)
....
[...
2
votes
2
answers
106
views
How to match line start and ending with specific text
I'm having a hard time with this regex. I'm trying to match the amount in the line starting with "Zahlbetrag" which ends with "CHF".
The text to search is:
Zwischentotal 0,00 ...
1
vote
1
answer
44
views
PHP: Cannot get regex pattern to repeat [duplicate]
I have an input string that looks something like this:
$txt = '!1 aaa !2 bb bb !5 cc cc cc !4 dd';
In other words, I have a number of fields, each starting with an exclamation mark and a digit.
It ...
0
votes
2
answers
84
views
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?
1
vote
1
answer
39
views
How to avoid extracting last specific character in which is part of regex group?
Given a command line
mycommand --optional-arguments their-values <patternOfInterestWithDirectoryPath> arg1 arg2
patternOfInterestWithDirectoryPath can be any of following
path/to/dir
/path/to/...
1
vote
0
answers
33
views
pcre_get_substring_list, match all pattern inside of string and return in array in Cwith PCRE
Hi try in C in linux with PCRE to match in this string"<test>a</test> <test>b</test> <test>c</Test>", the letter a,b,c i saw this script in stackoverflow ,...
1
vote
1
answer
39
views
Matching comparison operators indefinitely in a string
I'm trying to match the following pattern:
bla bla bla lorem ipsum bla bla email=destiney41@leuschke.org name!=Foo Bar
Here's my current approach:
(email|name)+\s*(>=|<=|>|<|=|!=)\s*([^ !=...
0
votes
1
answer
65
views
regexp with pcre in C how match all pattern?
i have create a script in C with PCRE in linux , for match a word in a string , it work, but now i want modify it because i want it match , all same word inside a phrases, for do that i do this ...
1
vote
5
answers
97
views
Regex Must Match a Word (not to replace) AND a Pattern (to replace) in a Line
With regex (can be PCRE or SED, but can also python[please specify]), I want to remove all occurrences of the lines that contain a single letter comma (/,.,/g) and with the word "Labels:"
So ...
1
vote
1
answer
88
views
How to reset entire match at the end of a capturing group?
Suppose I have the following text:
Yes: [x]
Yes: [ x]
Yes: [x ]
Yes: [ x ]
No: [x
No: x]
I am interested in a regex expression with two capturing groups as follows:
group $1: match the brackets [...
1
vote
1
answer
50
views
How to capture brackets with variable in-between amount of space as a single group?
Suppose I have the following text:
Yes: [x]
Yes: [ x]
Yes: [x ]
Yes: [ x ]
No: [
No: ]
I am interested in capturing the angular brackets [ and ] containing an x with a variable amount of ...
3
votes
1
answer
324
views
sudo pecl install mongodb problem | unknown type name 'pcre_cache_entry'
I'm trying to install mongodb exentsion for php 8.0.13 on my MacOS Monterey.
I try sudo pecl install mongodb command: and then get below errror.
/opt/homebrew/Cellar/php@8.0/8.0.13/include/php/ext/spl/...
3
votes
0
answers
408
views
Regex differences between PCRE and PCRE2
We're considering moving from PCRE to PCRE2 as our internal regex engine. Only the regex syntax itself is exposed to our users, so the library APIs differences are not an issue to our uses. However, ...
1
vote
1
answer
65
views
Global matching using PCRE
I try to match a comma-separated key-value pairs using PCRE. The text looks like this:
"key1": "value1", "key2": "value2"
and the tested pattern is:
/(\s*)(,?)&...
1
vote
4
answers
168
views
How to use capture groups with the `\K` reset match?
I found this question about using capture groups with the \K reset match (i.e., not sure if that's the correct name), but it does not answer my query.
Suppose I have the following string:
ab
With the ...
2
votes
2
answers
55
views
PCRE, match expression with *SKIP *F
In these two patterns:
1: abc)
2: a(bc)
I am trying to create a pattern that will match string 1 and return NULL if matched against string 2. I.e. only match if one right parenthesis is present with ...
2
votes
1
answer
154
views
Match non-word characters until enclosing non-word characters if found
I want to match any non-word character from the beginning and end position of a string, but if it comes across a non-word character which encloses a string, I want it to stop matching right before it.
...
0
votes
2
answers
543
views
Issue with a regex to validate the Nigerian phone numbering system
I’m working on a regex to match this set of numbers:
xxxx xxx xxxx
01 xxx xxxx
+234 1 xxx xxxx
xxxx-xxx-xxxx
xxxxxxxxxxx
234 xxx xxx xxxx
234(xxx)xxx-xxxx
234(xxx)xxx xxxx
+234(xxx)xxx xxxx
+234(xxx) ...
6
votes
1
answer
90
views
Why would you ever need (?(R)...|...) if condition in a regex?
I was looking though some regex documentation and was confused by something. The (R) condition in the context of (?(R)...|...) is said to be:
perl was a little cryptic:
(R)
Checks if the expression ...
1
vote
2
answers
55
views
preg_replace replace group #1
Assume the following string:
@twitter @handles @hello
Using the code below, I can replace the strings and generate links
preg_replace(
'/(?:^|[^>])(@' . $data->entities->user_mentions[$i]...
2
votes
3
answers
80
views
How can I get the first and last part of one wordcombination using regex
How can I get only the middle part of a combined name with PCRE regex?
name: 211103_TV_storyname_TYPE
result: storyname
I have used this single line: .(\d)+.(_TV_) to remove the first part: ...
1
vote
1
answer
101
views
Linux Bash grep extract word from matching string
I have numbers starging with a special character @ and ending with 900 and I now I want to extract the text in between excluding them.
My code:
>> cat demo.txt
asdfsdf
@ 1234900 asdf dfasd
asdf @...
0
votes
0
answers
79
views
Postfix header_checks
Is it possible to write postfix's header_checks in a way that would authorize lines like:
From: John Doe <john.doe@gmail.com>
From: John Doe <jdoe@myorg.com>
But would prevent lines like:
...
1
vote
1
answer
39
views
Regexp: find all occurences on same string inside brackets
i already few days trying write some regexp for replacing all : inside brackets, pls help me, so i have string:
render('MyBundle:Default:index.html.twig')
or render('MyBundle::Default::index.html.twig'...
1
vote
1
answer
59
views
PCRE matching catching subpatterns
I am embarrased I can't figure it out, so I have to ask. But let's say I have a string
where I want to match one OR two words. The first word must always be matched and the second word is sometimes ...
0
votes
0
answers
125
views
TACACS+ Pro Bono, how to fix You're using PCRE syntax?
I am trying to install tacacs+ by Pro Bono on Ubuntu 20.04. When I try to use pam as authentication I get this error when I try to start the tac_plus service:
Oct 05 14:46:19 server1 sudo[1165]: ...
0
votes
2
answers
63
views
php pcre regular expressions without delimiter
Background / Intro
Generally, regular expressions in PHP, e.g. for preg_match(), begin and end with a delimiter character like /. Personally I often used @ instead.
Instead of a delim character one ...
0
votes
1
answer
144
views
Nginx rewrite rule omit forward slash (/) when its first in encoded url
I'm trying to use Nginx (1.21.3) rewrite, but somehow it deletes the / key when it's first in string.
rewrite rule:
#nginx not relevant conf here
location / {
rewrite ^(.*)data/([0-9]+)/(.+)?$ $...