1

From the two urls

https://twitter.com/realDonaldTrump/status/829684271812067328

https://twitter.com/realDonaldTrump/status/829684271812067328/

I want to extract the String 829684271812067328 in Java. My attempt was

\\/status\\/([\\d]+)

but this does not allow anything before /status or after the digits (/).

Whats the solution to this?

fweigl
  • 21,278
  • 20
  • 114
  • 205

1 Answers1

0

If you just need to extract data (rather than validate the url format), I'd use the following regex :

(\\d+)/?$

And extract the first group of the result.

It matches a non-empty sequence of digits that can be followed by a / and must be found at the end of the matched text.

Aaron
  • 24,009
  • 2
  • 33
  • 57