Regex for code formatting - regex

I would like to add line feed after semi-comas in my text.
Something like replace(";",";\n\r")
But i need to exclude the semi-comas inside double quotes, how can i do this with regex?
In case of quotes i want this replacement:
var="Hello;World";
var="Hello;World";\r\n
and not this:
var="Hello;World";
var="Hello;\r\nWorld";\r\n
Thnak you!

You could do something like:
s/;(?=[^"\n]*(?:"[^"\n]*"[^"\n]*)*$)/;\n/gm; # perl synax
If there are no escaped quotes in the strings, and the strings do not span multiple lines.
That is replace:
;(?=[^"\n]*(?:"[^"\n]*"[^"\n]*)*(?m:$))
with
;\n

Related

Remove spaces in string under quotation in Notepad++ using RegEx

Suppose I have these strings:
'akshay ' ,
' ankur'
I want to remove trailing and leading spaces present under quotation mark like this:
'akshay',
'ankur'
How can I achieve this in Notepad++ using RegEX?
Use this to find: '(\s*)(.*?)(\s*)' and this to replace: '\2'.
Find this regexp: (^')\s+(\w+)\s*(')|(^')\s*(\w+)\s+(')
Replace with : \1\2\3\4\5\6
Like this:
All the RegExp given above solve my problem in a better way. I appreciate to all who helped me to solve this problem. Thank you everyone.
Here i am going to add a RegExp given below which can be used to count total number of spaces inside single quotation. It can be used to remove all spaces also.
Find--> \s(?!(?:[^']*'[^']*')*[^']*$) and ReplaceWith-->Nothing to do(leave blank) then click 'ReplaceAll'.

Regexp finding string enclosed by quotes

I have a little problem with VS2010.
So I want to find a certain strings between quotes with a Regexpression but only if the line doesn't contain a single "tr" or "QObject::tr" example:
I want to display all this lines:
Hallotr("asa");
("hhajkshjkas");
( _"hhajkshjkas" );
But don't want to display this lines:
tr("hhajkshjkas");
QObject::tr("hhajkshjkas");
My Regexp looks like this:
[^t-r]"[a-zA-Z0-9<>=\\"" ]* and ^[^tr]*"[a-zA-Z0-9<>=\\"" ]*"
but it shows all lines even if there is a single tr on the beginning of the string. Or it shows only lines which don't contain tr.
Thanks for help guys.
So I got the solution this is my regexp. :
^~((.*QObject.+tr)|(:b*tr:b*\()).*:q

Notepad++ Regular Expression Replace Quotes Between Quoted Columns in CSV

I have a comma separated CSV file with 3 quoted columns like this:
"this","is good","data"
Some rows have extra quotes in the second column:
"this","is "bad","data"
"this","is "really" bad","data"
This site (http://editplus.info/wiki/Search_and_Replace_Tricks#Delete_everything_inside_a_tag_pair_.28keeping_tags.29) has a RegEx string to select the text between tags ("," in this case), but I only want to replace any quote characters between the tags, not the whole string. Ideally I would only select those lines which have the offending quotes.
RegEx that selects whole second column:
(",").+(",")
RegEx that only selects the bad quotes or rows with them:
???
Any help is much appreciated. Thanks!
Ideally I would only select those lines which have the offending quotes.
^.*(?:,|^)"[^,"\n]*"[^,\n"]*".*$
DEMO
To replace the mismatched quotes with empty string, use the below regex.
([^,\n])"([^,\n])
Then replace the matched characters with \1\2
DEMO
Try this: It is tested in notepad++ for your all cases:
search by ([^,\n\r\t])"+([^,\n\r\t]) and replace with $1$2 (idea from #Avinash Raj)
Demo
Update for next requirement which is include comment
search by (^"|","|"$)|" and replace with $1
Update demo
Running a match using: /([\w ])"(?![,\n])/g
And substituting with: $1'
Replaces all offending double quotes with single quotes, producing:
"this","is 'bad","data"
"this","is 'really' bad","data"
Demo here: https://regex101.com/r/dL7jZ6/12 (Credit to Avinash Raj for finding the demo website)
Assuming the format is exactly how always how posted, I'd do something like:
[ ]".*?"

Remove more than one comma in between quotes in CSV file using Regex

all! Have CSV files coming in with with text inside double quotes that contain one or more commas and I am wondering if there is a regex form for Notepad++ that would remove any number of commas inside a CSV file.
For example I need to go from the this:
text,text1,"interesting, text,"
To this:
text,text1,"interesting text"
There can be 1,2 or more commas inside the quotes.
Anyone know a of a way to make this happen using regex form in Notepad++?
Thanks in advance!
use this pattern
,(?!(([^"]*"){2})*[^"]*$)
and replace with nothing
it is looking for a comma , that does not see an optional even number of double quotes " to the end of the string

Search and replace colon (:) between double quotes using regular expressions

I am fairly new to regular expression therefore this may be the simplest question you've seen on StackOverflow :-)
I have a large JSON file with text like this:
{..., "text": "BLAH BLAH", ...}
The text may contain any of the special characters and also characters like \", which I understand can be seen as escape character in regular expression. I am trying to find and replace a single character colon : with tilde ~ within the portion followed by "text" preferably in Notepad++. Any help will be greatly appreciated.
This regex will find all the : in the value for fields named text and replace the character with a ~. Note there were issues using regular expressions with Notepad++ v5. My demo here was tested in Notepad++ v6.3.3
Regex: ("text":\s"[^"]*?):
Replace with: $1~
Input string: {"not text": "12:34", "text": "BLAH:BLAH", "Never get a": ":oskupee"}
Here is what I did (thanks for all the help #Mike, but I had to make many edits. That's why I am answering my own question so other users can get the complete answer)
Search for \"text\": \".*? : .*?\", in Notepad++
Find and replace with \1~\2 to replace all : with ~
Manually correct the mistakes
You can do this:
find: ("(?:[^"]+|(?<=\\)")*")\s*:
replace: $1~
The idea is to capture the content inside double quotes, to put it in the replacement.
I use a lookbehind to allow escaped double quotes inside double quotes.