Simple Regular expression Java, brackets and doubles [closed] - java

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 6 years ago.
Improve this question
This is very basic but can't seem to find a answer when searching.
I have a string that's in the format:
[[[0.093493,51.6037],[0.091015,51.5956],[0.088596,51.5857]]]
The doubles inside the brackets are [latitude coordinate,longitude coordinate].
From this I'd like to extract the coordinates.
What should I put inside the search pattern if I use a Pattern/Matcher solution?
Assume that format with brackets is always correct but the doubles can vary in length.
Basicly what I want the code to do is:
Find "[" left of a number, then find this "," and return what's in between
AND another searchpattern that:
find "," and "]" and return what's inbetween.

Keep it simple by using this regex:
\[(\d+\.\d+),(\d+\.\d+)\]
and repeat the matcher.find() till all matches are found.
You matches are in group #1 and group #2
RegEx Demo

Related

Regex - Find all the digits that occur to a certain character [closed]

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 2 years ago.
Improve this question
I would like to ask you about regex expression - I need to get all numbers that occur to a certain character. For example:
"$z4~min.~00~s" -> 4
"$z12~min.~00~s" -> 12
I simply need first number in the string, I don't need numbers after dot in the string.
I am using Java for this project.
Do you have any suggestions? Thanks a lot.
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("^\\D*(\\d+)");
java.util.regex.Matcher matcher = pattern.matcher("$z12~min.~00~s");
if (matcher.find()) {
String firstNumber = matcher.group(1);
System.out.println(firstNumber);
}

Regular Expression to match first character and after a character [closed]

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 4 years ago.
Improve this question
I have the following string:
___abcd-metadata.json
I am trying to do a regex to get ___ and everything after -. So far I have this Regex:
(\-.*?\.json)
To find the last part and (___) to find the first part, but I have not been able to figure how to combine both regexes to make this happen.
My desired result would be ___ -metadata.json = true
"(\-)(.*)" is the pattern, which will give you 2 matches if the string contains them.
Take your string and use String.split('-') to break it into parts.
EDIT
var parts = ('_abcd-metadata.json').split('-'),
start = parts[0].substr(0,3),
rest = parts[1];

Is there a way to use \p{Punct}\p{Lower}\p{Upper} and in a regex(java), but without the "." character? [closed]

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 need to take out all the characters of a string that are not numbers.
You could use a Character Class Intersection like [\p{Punct}\p{Lower}\p{Upper}&&[^.]]
But why not just use
[^\d.]+
As Java String "[^\\d.]+"
This would match one or more characters, that are not \d a digit or the . period.
I'd suggest using \\d+ then (it's consecutive digits), and a capture group. Something like
String str = "";
str = str.replaceAll("(\\d+\\.\\d+)", "$1");

Regex java need some tips [closed]

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 7 years ago.
Improve this question
So I have to use Regex for the name of a character, where the name has to start with a capital and can only exist out of letters, apostrophe's and spaces.
And I dont know how to start, could anyone help me with this?
I suppose your character name is stored in a String variable. For that you can use the String.matches() function, which accepts a regex String parameter.
To create the required regex you will have to combine the folowing:
[A-Z] for the capital letter
[a-z' ]+ for the remaining characters.
Note that when using those in Java you'll need to add some escape characters
You can experiment with regular expressions here: http://www.regexr.com

How this regular expression do this? [closed]

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 8 years ago.
Improve this question
I want to use below expression in my program but i don't know what do this regular expression!
please help me.
"(?=(?!^)[,;.:])|(?<=[,;.:])"
in the above expression (?=(?!^)[,;.:]) find any character set that end with [.;,:] or no? what do this (?!^) in this expression?
and this expression find any character set that end with [,;.:] or no?
please help me.
The expression matches 0-length strings that satisfy one of these two conditions:
Ahead of it is one of ,;.:, but not for 0-length strings just before the beginning of the subject string (position 0). So the subject string "." has no match at position 0, only at position 1 because of the following alternative. This is done with positive lookahead (?=) and negative lookahead (?!).
Behind it is one of ,;.:. This is done with positive lookbehind (?<=).
For instance for "aaa,1", you have two matches: at position three (after the last a, because it's followed by ,) and at position 4 (because it's preceded by ,).

Categories