5

[Regex] How to get numbers without a letter before

 2 years ago
source link: https://www.codesd.com/item/regex-how-to-get-numbers-without-a-letter-before.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Regex] How to get numbers without a letter before

advertisements

at first I've only discover Regex few days ago...

And I am trying to use Regex to get digits/numbers but only if there is no letters. And even if the letters are before '('


Ex:

  • A = 3.2 => 3.2
  • AVariable5 = 3.0 => 3.0
  • vec(0,255)) => 0 & 255
  • vec2(0,0) => 0 & 0

Currently I am using the expression [\d.]+ to get digits with the '.'
I've tried few things, but no results, always getting more things or nothing.

So I'm asking to you how to do it and with explication if possible.
Thanks to you.

(Sorry if my english is bad)


\d+ is part of the story; what you need is a condition on the prefix, a look-behind, to require that the character before the match is not a letter:

\b(?<![A-Za-z])\d+([.]\d+)?

Demo.

Tags regex

Related Articles

How to get numbers of this type of string in C

1 13 3 4; 5 6 7 8; 9 10 11 12; 2 15 14 0 How can I get numbers from this string in ANSI C? I tried to separate it with strtok() : char *vstup = argv[1]; char delims[] = ";"; char *result = NULL; result = strtok( vstup, delims ); while( result !=

How to get information without using pyCURL (requests)

I need to implement the following curl: curl -k https://somelinkhere/get_info -d auth_info='{"session_id":"blablablaidhere"}' -d params='{"id":"12345"}' Currently I have the following code. It is working, but not ex

How to get content without nested elements with Nokogiri

src = '<paragraph>And bla foo <note>not important</note> bar baz</paragraph>' doc = Nokogiri::XML(src) puts doc.xpath('paragraph').first.content The code above returns: "And bla foo not important bar baz" I am looking for

How to get a date six months before the current date in a single line in Java?

I want to get a date six month before from present date. The code that I tried is: SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); Calendar c = Calendar.getInstance(); c.add(Calendar.MONTH, -6); System.out.println(format.format(c.g

How to get all the main characters before the first instance of a number

I have product codes that look like: abc123 abcd23423 I need to get all the leading characters before the first instance of a number, so: abc abcd What's the best way to do this? "abc123 abcd23423".scan(/(\D*)\d+/) => [["abc"], [&qu

Regex: How to get the file name without the first numbers?

I'm completely useless with regex in general with c-sharp: How can I parse away leading numbers in a filename? E.g. 413_somename.suffix. I need: _somename.suffix. How can I achieve this? thx! p.s.: Amount of numbers is one to n... Regex rgx = new Reg

Regex how to get a full match of the nth word (without using groups that are not captured)

I am trying to use Regex to return the nth word in a string. This would be simple enough using other answers to similar questions; however, I do not have access to any of the code. I can only access a regex input field and the server only returns the

perl regex: how to get open-reading-frames without stopping-internal codons?

I'm trying to isolate all overlapping ORFs from one strand of a (DNA) genome sequence in string format (including start (i) and stop (j) positions on the genome and length (l) of the ORF); the ORFs should start with ATG, have at least 24 internal nuc

PHP Regex - How to Get Multiple Words Between Analyzed Content

I am trying to fetch the latest "What's hot" topics from Alexa for my son's research project. I basically just want to grab the words and insert it into a mysql database. What I currently have is: <?php function getAlexa($url) { $ch = curl_in

HTML DOM: How to get items without losing kids?

I'm trying to perform a preg_replace on the text in an HTML string. I want to avoid replacing the text within tags, so I'm loading the string as a DOM element and grabbing the text within each node. For example, I have this list: <ul> <li><

Regex how to get the data out of json

I have a json array that I use in my application, and I need it elsewhere in that form so I have to keep it that way. I save it in a table inside my db ,and deserialize it when needed. But now I would like to do a query that filters some of that data

Java regex - How to get spaces and characters?

I am very confused on how Java's regular expressions work. I want to extract two strings from a pattern that looks like this: String userstatus = "username = not ready"; Matcher matcher = Pattern.compile("(\\.*)=(\\.*)").matcher(userst

How to get numbers with a prefix?

I have a single line of text that looks like "{\"Title\":\"Die Hard\",\"Year\":\"1988\",\"Rated\":\"R\",\"Released\":\"22 Jul 1988\",\"Runtime\":\"2 h 11 m

how to get numbers of a string in javascript?

I have "id": 1468306 inside of a string, how can I use regular expression to get the number 1468306 for it?You can use this regex: /: (\d+)/ as in: s = '"id": 1468306'; r = /: (\d+)/; console.log(r.exec(s)[1]); Output: 1468306

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK