vb.net regex - capture text between comms [duplicate] - regex

This question already has answers here:
Splitting a string on comma and printing the results
(3 answers)
Closed 6 years ago.
I am trying to extract the first three columns from these two lines of text.
A,Frequency,1.005 kHz,1.005 kHz,1.005 kHz,1.005 kHz,94.75 mHz,20,WholeTrace,
A,True RMS,1.404 V,1.403 V,1.404 V,1.403 V,232.6 æV,20,WholeTrace,
So what I would like displayed (extracted) form the above string is:
1.005 kHz
1.404 V
I found this post Regex exclusive capture between strings (VB.NET)
Which is seemingly doing something very similar, so I tried to modify that regex, however I am failing dismally (not least of all because I am really struggling to understand regular expressions!).
For mine, I tried
cy,\s+(\d+)\s+Hz\s+
But that doesn't work.
Could someone kindly help please?
This is in vb.net (VS 2013)

Using a Split function:
Dim value As String = Split("A,Frequency,1.005 kHz,1.005 kHz,1.005 kHz,1.005 kHz,94.75 mHz,20,WholeTrace,", ",")(2)

Related

How can I regex match a column in psql with or operators? [duplicate]

This question already has an answer here:
What regex matches any text that is entirely between square brackets?
(1 answer)
Closed 2 months ago.
I am trying to match a string containing a number, beginning with a [ or a space, and ending with a ] or a comma.
I have written the query as:
SELECT column FROM table WHERE column ~ '(\[| )1732529(\]|,)';
But the results contain rows where the entry includes other numbers as well such as: [1732604] or [1732561, 1738189].
I am expecting the return to include only rows where the entry matches the expression. For example: [1732529] or [1732529, 1728373]
Any advice on what I'm doing wrong with my regex is appreciated. This is my first time using it in psql.
Ended up getting a solution from ChatGPT to use the regex: r'^[[\s]1732529[],]' and it seems to work!

python regular expression splitting a string by all combinations of string starting with vowel [duplicate]

This question already has answers here:
How to get all overlapping matches in python regex that may start at the same location in a string?
(2 answers)
Closed 2 years ago.
problem
split a string by all combination where in each sub string starts with a vowels. For example a string like
BANANA need to be split into ANANA, ANAN, ANA, AN, A, ANA, AN, A, A
What I tried
import re
data_k=re.findall(r'(?=([AEIOU].*))','BANANA')
data_2=[s[:i] for s in data_k for i in range(1,len(s)+1)]
data_2
Do we have any faster method to do this , for large string they are giving me memory error, especially the second operation where I split each value in list.
Here is the solution without regular expression (but it only gives numbers of substrings in that string staring with vowel because If we try to get all combination then we will ends up with memory error for large strings.) .
(https://i.stack.imgur.com/aiA3j.jpg)!

Include 'Somestring' but excluding those that contain 'Otherstring' [duplicate]

This question already has answers here:
Regular expression for a string containing one word but not another
(5 answers)
Closed 3 years ago.
I was reading this SO post on excluding cases with a given string.
The selected answer there uses ^((?!hede).)*$ to exclude string 'hede'.
I have strings like the following:
apples_IOS_QA
apples_Android_QA
oranges
bananas
banannas_QA
apples_Android
apples_IOS
QA_apples_IOS // note sometimes 'QA' is at the beginning of the string
I'd like to return non QA versions of apples.
Tried (Within. Presto SQl Query):
and regexp_like(game_name, '^((?!QA).*$^apples.*)')
No results returned
Then tried:
and regexp_like(game_name, '^apples.*(!?QA)')
This runs and returns apples but gives me QA results only when in fact I wanted to exclude those results.
Then tried:
and regexp_like(game_name, '^apples.*[^(QA)]')
This returns apples results only but includes those with string 'QA' within them.
How can I regex filter to include 'apples' but exclude any cases that contain sub string 'QA'?
You may use this lookahead based regex:
^(?!.*QA).*apples.*$
(?!.*QA) is the lookahead assertion that needs to be placed next to ^ to that condition is applied to entire string since it has .* before QA.

I have two regex in .net preRegex = "(?<=(^|[^A-Za-z0-9]+))" postRegex = "(?=([^A-Za-z0-9]+)|$)" . What is the alternate of it in python? [duplicate]

This question already has answers here:
Python Regex Engine - "look-behind requires fixed-width pattern" Error
(3 answers)
Closed 5 years ago.
I have two regex strings in .net
preRegex = "(?<=(^|[^A-Za-z0-9]+))"
postRegex = "(?=([^A-Za-z0-9]+)|$)"
I want their alternative in python. My problem is let say I have a string
s="I am in aeroplane."
What I need is to replace "aeroplane with aeroPlain" so I want to make regex like
newKey = preRegex + aeroplane + postRegex
pattern = re.compile(newKey,re.IGNORECASE)
new regex string look like
(?<=(^|[^A-Za-z0-9]+))aeroplane(?=([^A-Za-z0-9]+)|$)
but it is giving me error "look-behind requires fixed-width pattern".
I am new to python, Help would be appreciated. Thanks
You can use the following regex:
(^|[^A-Za-z0-9]+)aeroplane([^A-Za-z0-9]+|$)
and when you replace, you can call the back reference to the first and second part of your regex to fetch their value.
Replacement string will be something like '\1aeroPlain\2'.
For more information on backref in python:https://docs.python.org/3/howto/regex.html
Good luck!

Regex find word and allow any characters after it in a string [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 7 years ago.
Ive got this string
designer-brand-paradise-design-t-9999-123990-tshirt-print-18-preorder-november-delivery
I need to extract any instance of preorder-* from it as I have a bit of a situation with alot of data lingering around.
Im new to regular expressions, so Im hoping this is an easy one. any help greatly appreciated
Looks like the regex you want to grab everything following preorder is:
preorder-(.*)
This will match the string preorder- and then everything past that is put into a group. Eg. in Java this would go:
Pattern preorder_pattern = Pattern.compile("preorder-(.*)");
Matcher m = preorder_pattern.matcher(my_string);
if(m.find()) {
// String my_string matches the pattern!
String stuff_after_preorder = m.group(1);
}