Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
For example
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
extract lines between 1cn8 to 1cn12
like this i have hundreds of line, want to extract any range by giving the input.
$ cat test | grep '[$0-9]'
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
these are node names, want to extract node names within the node range. lines starting from1cn8 till 1cn12
You can try something like that:
[[:alnum:]]{3}([8-9]|1[0-2])
Short explanation:
[[:alnum:]]{3}: matchs with any letter (upper or lower case) and digits, over 3 times;
([8-9]|1[0-2]): matchs with 8 and 9 [8-9] OR |, the number one with 0, 1 or 2, 1[0-2]
$ cat test
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
$ egrep '[[:alnum:]]{3}([8-9]|1[0-2])' test
1cn8
1cn9
1cn10
1cn11
1cn12
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
Require a shell script for the below issue
elecj_test: |1009676|F|269.13348200|3|348415|237.06|0.00|0.00|||SSPPPSSSPSSS|UNTESTED||
If a line starts with elecj_test: and ends with || it needs to replace with | |
Here Space is added in between | |
In the middle of the line if it is found || it must not replace only it must replace at end of the line.
You should show your attempt and the issue you are finding.
echo 'elecj_test: |1009676|F|269.13348200|3|348415|237.06|0.00|0.00|||SSPPPSSSPSSS|UNTESTED||' | sed '/^elecj_test:/s#||$#| |#'
This changes the last occurrence only (end of line: $).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Data:
BUY 2 FOR 5(STORES)
BUY 2 FOR 10(STORES)
What I tried:
regexp_extract(DATA, '.*? (\\d+) .*$', 2)
Desired result:
5
10
Like this:
regexp_extract(DATA, '^[^0-9]+?\\d+[^0-9]+?(\\d+)', 1);
or
regexp_extract(DATA, '^\\D+?\\d+\\D+?(\\d+)', 1);
Regex means: one or more Non-digits at the beginning, one of more digits, one or more non-digits, and finally the capturing group of digits, you need to extract the group number one.
One more solution is to split string by non-didits and take 2nd element:
select split(DATA, '[^0-9]+')[2];
Or even simpler:
select split(DATA, '\\D+')[2]; --\\D+ means one or more non-digits
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to use regex so as to obtain specific information from the text and I give an example with a semi-pseudocode ~ you can also reply me with semi-pseudocode:
list=["orange","green","grey"]
text= "The Orange is orange"
for word in list:
if word == re.compile(r'word, text):
capture Orange in order to have the noun
Beware! My question focuses whether there is a possibility to use variables (as word up above) so as to make a loop and see if there are equal words in an text based on a list.
Do not focus on how to capture the Orange.
I think Biffen has the right idea, you're in a world of pain if you're using this for POS tagging. Anyway, this allows you to match words in your text variable
for word in list:
if word in text:
# Do what you want with word
If you wanted to use regex then you can build patterns from strings, use parentheses to capture. Then use group() to access captured patterns
for word in list:
pattern = re.compile(".*(" + word + ").*")
m = re.match(pattern, text)
if m:
print(m.group(1))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
65 Gregory Street
;Gregory
141-145 Dickson Road
;Dickson
6B Malvern Avenue
;Malvern
230A John Street
;John
I'm trying to extract just the street name in a string, skip the numbers even ones with letters in them and just extract the first word in the string. What's the correct expression for this?
Skip the first group of non-space characters, get the next non-space group, skip the rest:
street := RegExReplace(address, "^\S+ (\S+).*$", "$1")
In case of multiline text you can process all lines at once with m and `a options:
streets := RegExReplace(addresses, "m`a)^\S+ (\S+).*$", "$1")
Use regex101.com to test the expressions online.
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'm not really good at regex or I can say that I'm a totally beginner to it. I want to know the regex from the following format:
LB-[0-999] - "LB-" with 0 - 999 digits and no spaces at the beginning, middle, and end.
XX-[0-19999] - Only two Capitalize letters in any combination with "-" and 0-19999 digits and no spaces at the beginning, middle and end.
XXX-[0-19999] - Only three Capitalize letters in any combination with "-" and 0-19999 digits and no spaces at the beginning, middle and end.
I want to get all three patterns but I'm really new to regex. I was planning to use it as html5 input validation and I'm really out of time of studying it.
This is what I tried so far:
^LB-[0-9]$
/LB\-[0-9]{1,3}/
/[A-Z]{2}\-1?[0-9]{1,4}/
/[A-Z]{3}\-1?[0-9]{1,4}/
With [0-9] you make appear only numbers in this set: 0 until 9 and with [A-Z] only capital letter from alphabeta. In {1,3} and {1,4} you make obligated to have at least one letter/number and at most four or three. With ?1 you make optional the present of a number 1 before your number, that will be present only for 10000 number or greater. This are three different er for each one of your possible entries.
Consider the changes prosed by user in his last comment the code will be like this:
/LB\-(00[1-9] | [1-9][0-9] | [1-9][0-9]{2})/
/[A-Z]{2}\-(0000[1-9] | 000[1-9][0-9] | 00[1-9][0-9]{2} | 0[1-9][0-9]{3} | 1[0-9][0-9]{3})/
/[A-Z]{3}\-(0000[1-9] | 000[1-9][0-9] | 00[1-9][0-9]{2} | 0[1-9][0-9]{3} | 1[0-9][0-9]{3})/