I want to use regular expressions in Kotlin and do the following:
"0012" == "12" // I want to make the above true
When comparing here, we are trying to compare after removing 00 of prefix in "0012" with regular expression.
As a result, it became as follows.
val reg = Regex ("0 * ([0-9] +)") reg.matchEntire ("00123") ?. groups? .get (1) ?. value == "123"
Is there a way to write this more concisely?
I would be grateful if you could tell me any good way.
Answer # 1
I don't know anything about the language, but as long as I google it,
"00123" .replace ("^ 0 *". toRegex (), "")
I think you can replace it like this.
Answer # 2
Do you compare with Int?
print ("123" .toInt () == "00123" .toInt ()) // =>true
Answer # 3
It is premised that no symbols are included, but it is embedded in regular expressions.
val a = "0012" val b = "12" a.matches (Regex ("0 * $b"))
- [ios] phone number validation (regular expression) error "cannot convert value of type'behaviorrelay' to expected argumen&q
- The regular expression replacement method of string in js
- Operators and description of regular expression tutorial
- Python regular expression method to intercept paired brackets
- Java regular expression method for special character escape
- IOS regular expression judgment input type (organization)
- Multiline (/ m) usage analysis in JS regular expression modifiers
- JS regular expression validation
- Practical regular expression matching and replacement
- Latest password validation regular expression
- Detailed regular expression syntax and form validation operations [based on JS]
- Explain the use of metacharacters in regular expression tutorials
- Detailed regular expression examples in java
- Detailed regular expression examples in PHP
- Regular expression to determine whether the color is legal (detailed)
- Explaining a set of characters in regular expression tutorial
- Detailed backreference reference of regular expression learning tutorial
- Regular expression implementation converts date in MM/DD/YYYY format to YYYY-MM-DD format
- Nginx if statement plus regular expression to achieve string truncation
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- android studio - unresolved reference comes out in kotlin
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- python 3x - import error "cannot import name '_imaging'"