LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2023, 08:33 PM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
Constructing a dynamic regex


I want to use the following variables

Code:
pbseq = "\[\{\("
qbseq = "\]\}\)"
to construct the following dynamic regex pattern

Code:
rl = "^[" pbseq "]|[" qbseq "]$"
What I get is

Code:
warning: escape sequence `\[' treated as plain `['
This could mean that I need some modification to pbseq and qbseq.

The idea is to construct

Code:
rl = "^[\[\{\(]|[\]\}\)]$"
using literal opening [{( and closing ]})

Last edited by Faki; 03-06-2023 at 08:51 PM.
 
Old 03-06-2023, 09:27 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,734

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Escape the slash?
Code:
pbseq = "\\[\{\("
 
Old 03-07-2023, 06:56 AM   #3
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
So the first backslash is used to escape the second backslash, which is itself used to escape the "[".

Does this apply also to all opening and closing brackets [ { ( ] } ) ?
 
Old 03-07-2023, 07:21 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
Quote:
Originally Posted by Faki View Post
So the first backslash is used to escape the second backslash, which is itself used to escape the "[".

Does this apply also to all opening and closing brackets [ { ( ] } ) ?
you need to understand how quotation works otherwise you will never know how to use those backslashes (if you need one, two or more of them).
Also you need to learn how quotation works to understand when do you need quote and what. It always depend on the actual context and language, there is no general answer.
 
Old 03-07-2023, 07:26 AM   #5
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
Can get quite complicated as you say, with multiple backslashes. As for the question I am constructing a dynamic regex that matches opening and closing literal brackets.

Code:
pbseq = "\\[\\{\\("  # Match literal opening brackets.
qbseq = "\\]\\}\\)"  # Match literal closing brackets. 
rl = "^[" pbseq "]|[" qbseq "]$"
What quotation workings need I understand, and what should I read exactly ?

Last edited by Faki; 03-07-2023 at 08:14 AM.
 
  


Reply

Tags
awk



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Need Help in constructing a script rajesh.bahl Linux - Server 1 06-05-2009 01:32 PM
Need Help in constructing a Script rajesh.bahl Linux - Security 1 06-05-2009 05:08 AM
constructing a beowolf cluster Goatdemon Linux - General 16 12-31-2005 11:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration