I need to extract the last occurrence of a substring enclosed in _()_, for example.
_()_
'a_long_(abc)_000' => abc 'a_long(string)_(def)_000' => def 'a_long_(string)_(abc)_blabla' => abc
Match with /_\((.*?)\)_/and take the last match:
/_\((.*?)\)_/
>> 'a_long_(string)_foo_(abc)_blabla'.scan(/_\((.*?)\)_/)[-1] => ["abc"]
Smth like this:
str[/.*_\((.*?)\)_/,1]
You can also use regex:
.*_\((.*?)\)_
Take a look
It:
\(([^\)]+)\)_[a-zA-Z0-9]*$
$1 should be your string
$1
Source: https://habr.com/ru/post/1785199/More articles:The difference between JodaTime and the calendar for the years before 1900 - javaJSON и логические значения - jqueryEncoding and decoding using UTF-8 on iPhone - iphoneDoes delphi TBitmap support alpha channel - delphivideo call in C # - c #iPhone - UIWebView - clicking on the URL before loading the page makes makeFailLoadWithError gives an error - iphoneRun SQL Script Against MySQL Using Powershell - mysqlWhat is the correct way to connect to a database from an eclipse plugin? - datasourceShow or burn preprocessor macros during build - macrosИзмените файлы конфигурации системы и используйте системные команды через веб-интерфейс - pythonAll Articles