Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10148

Check if String.matches() AND (if yes) extract number from String?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.erje.net!news.internetdienste.de!noris.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
From jochen2@brenz.com (Jochen Brenzlinger)
Newsgroups comp.lang.java.programmer
Subject Check if String.matches() AND (if yes) extract number from String?
Followup-To comp.lang.java.programmer
Date 21 Nov 2011 15:04:48 GMT
Lines 15
Message-ID <4eca6890$0$6569$9b4e6d93@newsspool3.arcor-online.net> (permalink)
Organization Arcor
NNTP-Posting-Date 21 Nov 2011 16:04:48 CET
NNTP-Posting-Host 46d32df0.newsspool3.arcor-online.net
X-Trace DXC=>iH1DEJYg09i6K;>iZ]763McF=Q^Z^V384Fo<]lROoR18kF<OcfhCO;@1JRC^ZeHH3QL4QcO2CM419AW^;nKDM<?0iX8<ZV`;Z:8iZH^To\P19
X-Complaints-To usenet-abuse@arcor.de
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10148

Followups directed to: comp.lang.java.programmer

Show key headers only | View raw


Assume I have a String var and value like:

String var = new String("foobar[345]");

Now I want to check if this string matches a certain pattern and if yes extract the number into a long var.
The first part is easy:

if var.matches("\\w*\[\\d+\]") {
   long l = ????;  }
   
...but I have no idea on how to extract the number.
How can this be achieved?

Jochen

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Check if String.matches() AND (if yes) extract number from String? jochen2@brenz.com (Jochen Brenzlinger) - 2011-11-21 15:04 +0000
  Re: Check if String.matches() AND (if yes) extract number from String? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-11-21 07:33 -0800
  Re: Check if String.matches() AND (if yes) extract number from String? Tassilo Horn <tassilo@member.fsf.org> - 2011-11-21 16:45 +0100
  Re: Check if String.matches() AND (if yes) extract number from String? Henk van Voorthuijsen <voorth@xs4all.nl> - 2011-11-21 07:39 -0800
  Re: Check if String.matches() AND (if yes) extract number from String? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-21 10:26 -0800
  Re: Check if String.matches() AND (if yes) extract number from String? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-21 11:43 -0800

csiph-web