Regex to Remove Empty Line and Number - regex

I am having trouble removing the number following an empty line using Regex. Here's the sample paragraph that I have:
1
- Lorem Ipsum is simply dummy text of
2
the printing and typesetting industry.
49
and more recently with desktop publishing software like Aldus PageMaker.
I need to remove all the numbers from the beginning of the sentence as well as the empty lines:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. and more recently with desktop publishing software like Aldus PageMaker.
This is the regex that I can think of [\n](.) ,but it can only remove one digit of number
The difficult part is to remove the number because the number of digits are not necessary 1 or 2 digits. How do I tackle this problem?

Do a regex replace of the following regex with blank:
^\d*\n
See live demo.

Related

I can't find a regex to get '(% number%)' in string with php [duplicate]

This question already has answers here:
Regular expression to return text between parenthesis
(11 answers)
Regular expression to find number in parentheses, but only at beginning of string
(2 answers)
Regular Expression to get a string between parentheses in Javascript
(10 answers)
Closed 1 year ago.
I can't find a regex to get '(% number%)' in string.
For example I would like to get (100), (2000) ... inside the following string:
Lorem Ipsum is simply dummy text (100) of the printing and typesetting
industry. Lorem Ipsum has been the (2000) industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to (40) make a type specimen book. It has
survived not only five centuries, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularized in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.

regex big query extracting numeric from url

Hello I am trying to extract the 7digit with a big query for extracting the 2670782 and 2670788
on this data
desc field data below
is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type 8888888 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing 8888888 software like Aldus PageMaker including versions of Lorem Ipsum.
>> https://hello.com/pudding/answer/2670782?hl=en&ref_topic=7072943
>> https://hello.com/pudding/answer/2670788?hl=en&ref_topic=7072943
I have a query but there are also other 7digit number on the data other than the 2670782 and 2670788. so first I wanted to check if the line starts with ">>" and includes "hello.com" and I can extract it.
Here is the query that I have but it will grab the 8888888 as well which is not supposed to be.
SELECT
desc,
REGEXP_EXTRACT_ALL(desc, r"\/(\d{7})") AS num
FROM
`table`
WHERE
REGEXP_CONTAINS(DESCRIPTION, r"(>> )")
AND REGEXP_CONTAINS(desc, r"(hello.com)")
I believe I need to check if the line starts with >> and it contains hello.com in a single regex formula and then I can extract the 7 digit number after the /. I am stuck so
Any help would be much appreciated!!
You can use this regex if each of your inputs is one line
^>>.+hello.com.+\/(\d{7})
I test this regex in regex101.com with your input and the 1-line input assumption
UPDATE:
You can replace the ">>" with newline character, then use the below regex to extract the number
hello.com.+\/(\d{7})
Here is the example:
WITH
sample AS (
SELECT
'''start here not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing 8888888 software like Aldus PageMaker including versions of Lorem Ipsum. >> hello.com/pudding/answer/2670782?hl=en&ref_topic=7072943 >> hello.com/pudding/answer/2670788?hl=en&ref_topic=7072943
''' AS txt
UNION ALL
SELECT
'''
is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type 8888888 specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing 8888888 software like Aldus PageMaker including versions of Lorem Ipsum.
>> https://hello.com/pudding/answer/2670786?hl=en&ref_topic=7072943
>> https://hello.com/pudding/answer/2670785?hl=en&ref_topic=7072943
'''),
sample_new_line AS (
SELECT
REGEXP_REPLACE(txt, '>>', '\n') AS txt
FROM
sample)
SELECT
REGEXP_EXTRACT_ALL(txt, r"hello.com.+\/(\d{7})") AS num
FROM
sample_new_line;

Match multiple lines usign Regex

I'm having the below text.
^0001 HeadOne
##
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
^0002 HeadTwo
##
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
^004 HeadFour
##
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
^0004 HeadFour
##
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been theindustry's standard dummy text ever since the 1500s, when an unknown printer took a galley of typeand scrambled it to make a type specimen book.
Below is the regex I'm using to Find.
##([\n\r\s]*)(.*)([\n\r\s]+)\^
but this is catching only ^0001 and ^0003 as these have only one paragraph, but in my text there are multi para contents.
I'm using VS code, can someone please let me know how can I capture such multi para strings using REGEX in VS code or NPP.
Thanks
One weird thing about VSCode regex is that \s does not match all line break chars. One needs to use [\s\r] to match all of them.
Keeping that in mind, you want to match all substrings that start with ## and then stretch up to a ^ at the start of a line or end of string.
I suggest:
##.*(?:[\n\r]+(?!\s*\^).*)*
See the regex demo
NOTE: To only match ## at the start of a line, add ^ at the start of the pattern, ^##.*(?:[\s\r]+(?!\s*\^).*)*.
NOTE 2: Starting with VSCode 1.29, you need to enable search.usePCRE2 option to enable lookaheads in your regex patterns.
Details
^ - start of a line
## - a literal ##
.* - the rest of the line (0+ chars other than line break chars)
(?:[\n\r]?(?!\s*\^).*)* - 0 or more consecutive occurrences of:
[\n\r]+(?!\s*\^) - one or more line breaks not followed with 0+ whitespace and then ^ char
.* - the rest of the line
In Notepad++, use ^##.*(?:\R(?!\h*\^).*)* where \R matches a line break, and \h* matches 0 or more horizontal whitespaces (remove if ^ is always the first char on a delimiting line).
I plugged your input data into /tmp/test and got the following to work using perl syntax
grep -Pzo "##(?:\s*\n)+((?:.*\s*\n)+)(?:\^.*)*\n+" /tmp/test
This should be placing the paragraphe not starting with ^ into $1. You may need to add \r back into this to make it match perfectly

regex how to find two or more indentical lines with one line between in a file

i have some files and must find identical lines starting with "abc" and exact one line between these two identical lines.
lorem
abcdefg
lorem
abcdefg
lorem
lorem
abcdefg
abcdefg
lorem
lorem
in this sample the lines 2 and 4 should match but not then lines 4 and 7 and not the lines 7 and 8. is it possible?
Since you don't say the language I would do something like:
abc([^\n]+)\n[^\n]*\nabc(\1)
which checks for:
Letters abc.
a captured group without new lines.
The new line character.
A complete new line.
The new line character.
The previously matched first group content.
Check if its available for your language:
http://www.regular-expressions.info/refext.html (for instance in .NET this is not valid).

How can I create a regex to parse this string

how can I make a regex to parse this string ?
"desc: random text string, sender: James, se-status: red, problem-field: I'm a problem field, I'm a problem field, action: runs, target: John, ta-status: blue, status-apply: red, lore: lore ipsum dolor sit amet"
I want groups that get keys and values. Please note the "problem-field" has quotes in it. The groups should get the key and then locate the last comma before the next key name.
This is an example string. Other strings can have different field names, so the regex shouldn't match specific field names like sender or action.
expected result groups:
1. "desc"
2. "random text string"
3. "sender"
4. "James"
5. "se-status"
6. "red"
7. "problem-field"
8. "I'm a problem field, I'm a problem field"
9: "action"
10."runs"
11."target"
12."John"
13."ta-status"
14."blue"
15."status-apply"
16."red"
17."lore"
18."lore ipsum dolor sit amet"
Please note problem field should be 1 result only
This question started when I tried to improve my answer to this SO question here: JS: deserializing a string with a JSON-like structure
I have done a classic for, but then user Redu created a regex based answer. Yet I didn't like because the field names had to be fixed. So I tried to create a regex with capturing groups that go back to check last comma, but I quickly discovered that my regex skills don't go that far (yet). So I thought in creating this question so we can learn with the regex masters out there.
This regex could help you:
([\w-]+): ([\w,\s']+)(?:,|$)
Demo
It capture every key/value separated with a :