0

I have a link and I wanna number in this link.

<a title="HALKALININ EN G&#214;ZDE PROJESİ BOSPHORUS CITYDE SAHİBİNDEN SATILIK" class="overlay-link" href="/konut-satilik/istanbul-kucukcekmece-halkali-merkez-sahibinden-apartman-dairesi/detay/25118422"></a>

I tried

content.replaceAll("[^-?0-9]+", "")

but output is wrong. I wanna numbers after /detay/

output:

214--------25118422
Ahmed Ashour
  • 4,209
  • 10
  • 29
  • 46
Johny
  • 21
  • 1
  • Please tell us what you tried and provide some sample code where you got stuck. – Psi Mar 05 '17 at 13:00
  • `/\d+$/` ........ if look-behind supports then `/(?<=-)\d+/` – Pranav C Balan Mar 05 '17 at 13:00
  • Welcome Johny. Please show your code that didn't work and specify regex flavor. Most people here don't answer "give me regex" questions as long as they aren't interesting problems or show at least a bit of own research effort :) – bobble bubble Mar 05 '17 at 13:06
  • @PranavCBalan it doesn't worked. – Johny Mar 05 '17 at 13:15
  • @bobblebubble ty. I edited question. – Johny Mar 05 '17 at 13:16
  • @Psi I am new in regex. I read some topics in stackoverflow but they didn't worked for me. – Johny Mar 05 '17 at 13:17
  • 3
    If you just need the number after `/detay/` how about using a [capturing group](http://www.regular-expressions.info/brackets.html) for extraction like this: `/detay/(\\d+)` with [`find()`](http://stackoverflow.com/a/600740/5527985) -> `group(1)`. Also see [regex reference here](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean). – bobble bubble Mar 05 '17 at 13:31
  • @bobblebubble it worked. ty :) – Johny Mar 05 '17 at 14:28

1 Answers1

0

You can use regular expression for extracting the ID from the link. See the example below:

    String content = "<a title=\"HALKALININ EN G&#214;ZDE PROJESİ BOSPHORUS CITYDE SAHİBİNDEN SATILIK\" class=\"overlay-link\" href=\"/konut-satilik/istanbul-kucukcekmece-halkali-merkez-sahibinden-apartman-dairesi/detay/25118422\"></a>";

    Matcher matcher = Pattern.compile("/detay/([0-9]+)").matcher(content);

    String linkId = null;
    if (matcher.find()) {
        linkId = matcher.group(1);
    }

    System.out.println("linkId: " + linkId);

Hope this helps!

anacron
  • 5,733
  • 2
  • 21
  • 31