perl nested regex [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Text record:
(1,2,3,4,{fred,don,max,rat,grp},45,67,mat,jhon,{a,b,1,2,sd[{1,2},{4,5}],45,67,P[{34,56,34},{uni,cast,r}],c{q,ew,3,4},1,2,3,cf{2,4,5,8},6},4,fr{24,45,67},5,NOL)
Desired output:
(1,2,3,4,{fred:don:max:rat:grp},45,67,mat,jhon,{a:b:1:2:sd[{1:2}:{4:5}]:45:67:P[{34:56:34}:{uni:cast:r}]:c{q:ew:3:4}:1:2:3:cf{2:4:5:8}:6},4,fr{24:45:67},5,NOL)
needs to be replace by : for the below:
Everything between {} and []
The data has nested structure like {{}} and {[],[]}
The text record is always between ().
Any help with perl is appreciated.

You may try the below perl command which uses positive lookahead based regex.
perl -pe 's/,(?=(?:\{[^{}]*\}|[^{}])*})|,(?=(?:\[[^\[\]]*\]|[^\[\]])*\])/:/g' file
DEMO

Related

How to move ip adresses to the end of line in Notepad++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have the data as follows in txt:
136.40.226.97|ubnt|ubnt|
138.197.81.94|listd|54e172662|
138.68.254.243|wordpress|wordpress|
139.162.55.12|public|public|
139.60.58.136|system|OkwKcECs8qJP2Z|
I want to convert it to this:
|ubnt|ubnt|136.40.226.97
|listd|54e172662|138.197.81.94
|wordpress|wordpress|138.68.254.243
|public|public|139.162.55.12
|system|OkwKcECs8qJP2Z|139.60.58.136
In Find and Replace window Ctrl+H change Search Mode to Regular expression and set:
Find what: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(.*)
Replace with: (\2)(\1)
This will find too groups: IP(1), rest of line(2), then Replace writes them in inverted order.

Use sed to print lines that start with z and do not end in 03 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to print the lines in a text file using the sed command that start with z and do not end in 03. Any help would be appreciated.
This is one way to do this
sed -n '/^z/ { /03$/! p }' <file.txt

how we can delete numbers in between two matching pattern using sed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a file something like:
INSERT INTO abc VALUES (0,'edwe','edwe',NULL,'2017-10-24 03:00:00','2017-10-24 03:00:00'),(1,'City','Delhi',NULL,'2017-10-24 03:00:00','2017-10-24 03:00:00'),(4,'artType','Advice/Opinion',NULL,'2017-10-24 03:00:00','2017-10-24 03:00:00')
How can I use a sed command to delete the numbers in between "(" and ","(occurrence of first comma only and delete it as well) So that result will become:
INSERT INTO abc VALUES ('edwe','edwe',NULL,'2017-10-24 03:00:00','2017-10-24 03:00:00'),('City','Delhi',NULL,'2017-10-24 03:00:00','2017-10-24 03:00:00'),('artType','Advice/Opinion',NULL,'2017-10-24 03:00:00','2017-10-24 03:00:00')
Use
sed 's/([0-9][0-9]*,/(/g' yourFile

A simple regex call to replace some text in Eclipse [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need help with a really simple regex find/replace command for Eclipse. It'd be great if you could provide me with something to try.
I need to replace all occurrences of the text typeSingleton(*) ), with typeSet({ * } ).
Assume that inside brackets you may have letters, brackets, spaces, then:
Find: typeSingleton\(([a-z ]+(\([a-z ]+\))? ?)\)
Replace: typeSet({$1})
EDIT
Demo: https://regex101.com/r/dD0wK0/1

C# Regex Replace string with Ignore specific word [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have File and I want to replace fix character * : ~ with # using regex but, it should not replace(ignore) B~~ word because, it need to remain as it is. Anybody have idea for that?
Input :
ABCHKLJNKL*dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm:skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK
Output Should be :
ABCHKLJNKL#dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm#skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK
Please provide regex because i want to done with one step.
Thanks
[*:]|(?<!B[~])[~](?![~])
Try this.This should do it.See demo.Replace by #.
https://regex101.com/r/tX2bH4/66