How to create a newline above text that has a question mark? - regex

I was wondering if anyone could help with this. I'm new to regex so I'm not sure exactly how to do this. I'm using Notepad++. Essentially what I want to do is every time there is an instance where there is a sentence ending with a question mark (?), I would like to create a new line above it.
E.g:
Junk text
Junk text
Junk text
Which of the following statements about the species diversity index is <strong>true</strong>?
I would like to appear like:
Junk text
Junk text
Junk text
Which of the following statements about the species diversity index is <strong>true</strong>?
Any one have any suggestions? Thanks in advance!

You could replace ^(.*\?) with \n\1.
^(.*\?) matches lines with a ?.

find: .*[?]$
replace with : \n$0
of course you need check the Regular expression button in replace tab.

You can do this:
Find and replace
Check regular expression checkbox at search mode
Search for : ^(.*)\?$
Replace with: \n\1?
Example:
a
b
c?
d
e?
f
Output:
a
b
c?
d
e?
f

With regex, you should replace
(.*)\?$
With
\r\n\1?
Does that do the trick?

Related

Notepad++ RegEX how do I append a character based on start of the character and before a character?

I would like to append _OLD to the end of each strings that starts with SR_ but before the symbol ' or without it
For example my text is the following:
SR_Apple
When the 'SR_APPLE' rotten, we must discard it.
I would like the find and replace to do:
SR_Apple_OLD
When the 'SR_APPLE_OLD' rotten, we must discard it.
I have tried (SR_*)+$.*(?='\s) based on what i Learned but no luck so far. Please help. Thx in Adv
For simple cases you should be able to use
Find: (\bSR_[\w]+)
Replace: $1_OLD
(\bSR_.+?)('|$) and $1_OLD$2 could also work if the text after SR_ is more complex
The lookbehind you're using is only matching the string if it ends with a ' so it won't find the text not in quotes.
regex101 is a useful tool for debugging expressions

In Notepad ++: Replacing some string with something else in all the lines containing another string

In the example below, is there any way to place a string like ("1one1") before {",} at the end of all lines which contain {ī}?
īn:"ZZin",
ín:"FFin",
ǐn:"QQin",
ìn:"TTin",
ie:"XXie",
iē:"TTie",
ié:"GGie",
Thanks
Using Notepad++ regex search for ^(.*ī.*)(",)$ and replace with \11one1\2.
You will need to use regex regex for notepad++.
so, mark "Regular Expression" in the final of Replace box.
in your fields to search:
find what: ī.[^"]"([A-Za-z0-9]*)
replace with: īn:"\11one1
i think it will do what you want. Let me know if it doesn't to edit the regex.

How to search and replace with regex in Notepad++

I have a txt files with some lines containing GPS data, which I need to shorten.
So I have
5|{"mResults":0.0|0.0|"mProvider":"fused"|"mDistance":0.0|"mTime":1395061255413|"mAltitude":161.0|"mLongitude":29.0459152|"mLon2":0.0|"mLon1":0.0|"mLatitude":41.0854122|"mLat1":0.0|"mLat2":0.0|"mInitialBearing":0.0|"mHasSpeed":true|"mHasBearing":false|"mHasAltitude":true|"mHasAccuracy":true|"mAccuracy":15.0|"mSpeed":0.425211|"mBearing":0.0}|1395061255413
and I need to extract only the coordinates,
so convert it into this :
29.0459152|41.0854122
Edit:
Turns out I need this:
GPS|29.0459152|41.0854122|0|1395061255413
Please note that I need to :
add GPS| in front, and |0 at the end.
and also I need to append the timestamp value (the last value in the original one) |1395061255413
How can I do this with Notepad++?
Thanks for any help !
Here is how you could do that in Notepad++:
use Ctrl+H to open the Replace pop-up
tick Regular expression in the Search mode section
search for this pattern: .*?"mLongitude":(\d+(?:\.\d+)?).*?"mLatitude":(\d+(?:\.\d+)).*
replace the matched string by \1|\2
click on Replace all ;)
How it works:
The regex pattern featured in my answer extracts the values for the longitude and latitude from each line and replaces the whole line by:
the mLongitude value,
a literal "|" and
the mLatitude value.
Would you like to have this pattern explained in more details, please check out this permalink on regex101.
EDIT:
To include the timestamp you're referring to, you need to use this regex:
.*?"mLongitude":(\d+(?:\.\d+)?).*?"mLatitude":(\d+(?:\.\d+)).*\|(\d+)
Then, you just have to change the formatting of your replacement string to this:
GPS|\1|\2|0|\3
You probably got that already but let's still write down the complete usable solution ;)
I hope this helps!
I solved my problem by this :
search:
.*?"mTime":(\d+(?:\.\d+)?).*?"mLongitude":(\d+(?:\.\d+)).*?"mLatitude":(\d+(?:\.\d+)).*
replace :
GPS|\2|\3|0|\1
But this is because the same data (timestamp) was also inside the string. So this does not extract the timestamp from the end, but from the middle of the string.
So if #ccjmne edits the answer that extracts it from the end, I will accept that answer.

replacing all open tags with a string

Before somebody points me to that question, I know that one can't parse html with regex :) And this is not what I am trying to do.
What I need is:
Input: a string containing html.
Output: replace all opening tags
***<tag>
So if I get
<a><b><c></a></b></c>, I want
***<a>***<b>***<c></a></b></c>
as output.
I've tried something like:
(<[~/].+>)
and replace it with
***$1
But doesn't really seem to work the way I want it to. Any pointers?
Clarification: it's guaranteed that there are no self closing tags nor comments in the input.
You just have two problems: ^ is the character to exclude items from a character class, not ~; and the .+ is greedy, so will match as many characters as possible before the final >. Change it to:
(<[^/].+?>)
You can also probably drop the parentheses and replace with $0 or $&, depending on the language.
Try using: (<[^/].*?>) and replace it with ***$1

First occurrence of a character in string. Regular expression needed

I have some CSV data like this:
1325318514,197.1,184.9,172.4,146.0,147.3,131.1,280.9,182.7,12.6,5.0,0.0,73001,65848,0
1325318536,196.2,184.2,172.1,146.3,147.1,131.1,264.9,175.6,12.6,5.0,0.0,71590,64616,0
1325318557,196.6,184.9,172.1,147.6,146.8,130.9,264.9,178.4,12.6,5.0,0.0,69607,61274,0
1325318578,196.7,184.2,172.1,148.4,146.8,130.6,255.9,174.0,12.5,5.0,0.0,74127,59221,0
....
i want to replace the first , with a space on each string but not the rest of the ,s
Any ideas on the regexp for that? Tried a few different things and just cant seem to get it to work...
your question is not very clear, I just give an example, hope it is helpful for you:
sed 's/,/ /1' <<<"1325318514,197.1,184.9,172.4,146.0,147.3,131.1,280.9,182.7,12.6,5.0,0.0,73001,65848,0
1325318536,196.2,184.2,172.1,146.3,147.1,131.1,264.9,175.6,12.6,5.0,0.0,71590,64616,0
1325318557,196.6,184.9,172.1,147.6,146.8,130.9,264.9,178.4,12.6,5.0,0.0,69607,61274,0
1325318578,196.7,184.2,172.1,148.4,146.8,130.6,255.9,174.0,12.5,5.0,0.0,74127,59221,0"
output:
1325318514 197.1,184.9,172.4,146.0,147.3,131.1,280.9,182.7,12.6,5.0,0.0,73001,65848,0
1325318536 196.2,184.2,172.1,146.3,147.1,131.1,264.9,175.6,12.6,5.0,0.0,71590,64616,0
1325318557 196.6,184.9,172.1,147.6,146.8,130.9,264.9,178.4,12.6,5.0,0.0,69607,61274,0
1325318578 196.7,184.2,172.1,148.4,146.8,130.6,255.9,174.0,12.5,5.0,0.0,74127,59221,0
In most regex implementations, use the pattern
/([^,]*),(.*)/gm
And replacement text
$1 $2
See it online at http://refiddle.com/1ot