This is my string
username=john903?fullname=john&smith
This is my regex so far
=([^?]*)
I am trying to capture "john903"
However this currently returns "=john903"
This is my string
username=john903?fullname=john&smith
This is my regex so far
=([^?]*)
I am trying to capture "john903"
However this currently returns "=john903"
Javascript: (Originally the question was tagged with Javascript)
The regex you have currently captures the value you want, but returns an array. The match without the equal sign is in the second element of the array:
var str = "username=john903?fullname=john&smith".match(/=([^?]*)/)[1]
//str is now "john903"
Java: (OP commented they are in fact using Java)
String line = "username=john903?fullname=john&smith";
Pattern pattern = Pattern.compile("=([^?]*)");
Matcher matcher = pattern.matcher(line);
System.out.println(matcher.group(1));
You need to utilize positive lookbehind to achieve this. Reference
and here's a fitting regex
(?<==)([^?]*)