Get substring using regex

Семен Немытов

I have some strings Like

1.IND_FROM_ONE_TO_FIVE  
2.IND_FROM_FIVE_TO_TEN  
3.BS_FROM_ONE_TO_FIVE 
4.BS_FROM_FIVE_TO_TEN   
5.OP_FROM_ONE_TO_FIVE  
6.OP_FROM_FIVE_TO_TEN

And I want to cut from all of them everything before the first "" include ""!!!.

Something like :

1.IND_FROM_ONE_TO_FIVE => FROM_ONE_TO_FIVE

2.IND_FROM_FIVE_TO_TEN => FROM_FIVE_TO_TEN

3.BS_FROM_ONE_TO_FIVE => FROM_ONE_TO_FIVE

4.BS_FROM_FIVE_TO_TEN => FROM_FIVE_TO_TEN etc.

I have tried /[^_]*/ but it returns IND_FROM_ONE_TO_FIVE => _FROM_ONE_TO_FIVE (did not cut first "_")

How could I make it on java?

The fourth bird

You can prepend an anchor and match the underscore after is as well. In the replacement use an empty string.

^[^_]*_

Regex demo | Java demo

Using replaceFirst you can omit the anchor:

System.out.println("IND_FROM_ONE_TO_FIVE".replaceFirst("[^_]*_", ""));

Output

FROM_ONE_TO_FIVE

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Regex: get number after and before specific substring

分類Dev

how to get text with using substring

分類Dev

Lua - Get first occurrance of substring using a pattern

分類Dev

Extracting substring from PDF raw text using regex

分類Dev

python : Using regex to get episode

分類Dev

Regex multiple match substring

分類Dev

regex match substring unless another substring matches

分類Dev

Regex for strings containing substring that contains substring

分類Dev

Get envelopeID from a string using regex

分類Dev

Get the quantity from the description in Pyspark using regex

分類Dev

How to get Instagram post id by using Regex?

分類Dev

Get last part of url using a regex

分類Dev

Regex: Getting Variable from Substring

分類Dev

Javascript Extract from substring regex

分類Dev

Get a substring in hive

分類Dev

Java Get substring of a string

分類Dev

Regex: How to remove a substring that is bounded by certain characters?

分類Dev

Creating a Regex expression with a “not” condition for a specific substring

分類Dev

Get length of Substring from string

分類Dev

Using Regex to get string between lookbehind and lookahead with brackets and parenthesis in it

分類Dev

How to get the Hello "Newline" and World in powershell using regex?

分類Dev

get word from string but not in html tags using python regex

分類Dev

bash/sed script to get output from a file using a regex

分類Dev

Parse a JS script using PHP and REGEX to get a JS variable value

分類Dev

Get all alphabets in a string of words using regex (including spaces)

分類Dev

Find substring of keyword using BeautifulSoup

分類Dev

Replace substring in a string using a list

分類Dev

Substring in c without using functions

分類Dev

Using DISTINCT, COUNT AND SUBSTRING in a statement

Related 関連記事

  1. 1

    Regex: get number after and before specific substring

  2. 2

    how to get text with using substring

  3. 3

    Lua - Get first occurrance of substring using a pattern

  4. 4

    Extracting substring from PDF raw text using regex

  5. 5

    python : Using regex to get episode

  6. 6

    Regex multiple match substring

  7. 7

    regex match substring unless another substring matches

  8. 8

    Regex for strings containing substring that contains substring

  9. 9

    Get envelopeID from a string using regex

  10. 10

    Get the quantity from the description in Pyspark using regex

  11. 11

    How to get Instagram post id by using Regex?

  12. 12

    Get last part of url using a regex

  13. 13

    Regex: Getting Variable from Substring

  14. 14

    Javascript Extract from substring regex

  15. 15

    Get a substring in hive

  16. 16

    Java Get substring of a string

  17. 17

    Regex: How to remove a substring that is bounded by certain characters?

  18. 18

    Creating a Regex expression with a “not” condition for a specific substring

  19. 19

    Get length of Substring from string

  20. 20

    Using Regex to get string between lookbehind and lookahead with brackets and parenthesis in it

  21. 21

    How to get the Hello "Newline" and World in powershell using regex?

  22. 22

    get word from string but not in html tags using python regex

  23. 23

    bash/sed script to get output from a file using a regex

  24. 24

    Parse a JS script using PHP and REGEX to get a JS variable value

  25. 25

    Get all alphabets in a string of words using regex (including spaces)

  26. 26

    Find substring of keyword using BeautifulSoup

  27. 27

    Replace substring in a string using a list

  28. 28

    Substring in c without using functions

  29. 29

    Using DISTINCT, COUNT AND SUBSTRING in a statement

ホットタグ

アーカイブ