Regular expressions for all occasions

  • Автор темы Автор темы LightWood
  • Дата начала Дата начала

LightWood

Moderator
Регистрация
04.11.2010
Сообщения
2 382
Реакции
917
Баллы
113
We collect the people's list of regulars (regex) for all occasions, I'll start first. Who has their own - throw, add to the first post indicating the author. Regulars can sometimes work incorrectly, if that write off in this thread - we will find a solution.

[TABLE="class: brtb_item_table, border-width: 4px"][TBODY][TR][TH]List of regular expressions and typical usage contexts[/TH][/TR]
[TR][TD]Search for a number greater than 0
Код:
Развернуть Свернуть Копировать
(?<=(\D|^))[1-9]\d*

Use case:
Снимок экрана от 2017-12-03 17-09-18.png


In this example, the visible elements are searched for only, the invisible elements (having a width of 0px) are ignored, but sometimes there are misfires - when a site overlays elements (it is found in Google for example).

Thanks: CSS, ZennoScript[/TD][/TR]
[TR][TD] Parsing the text for sentences, seems author is ZennoScript, I have slightly modified
Код:
Развернуть Свернуть Копировать
[А-ЯA-Z].{15,}?(\.|\!|\?)(?=\ |\r|\n|$)

work example, initial data:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce dapibus tellus nec nulla gravida, sed congue nunc hendrerit. Integer interdum elementum lorem id rutrum. Ut sit amet interdum mauris. Phasellus mollis ex eleifend lacus molestie dictum. Fusce blandit, ligula non condimentum maximus, massa nisi ullamcorper odio, et vehicula nisl nunc nec orci. Sed neque diam, gravida eu blandit ullamcorper, porttitor non lorem. Etiam sagittis diam a dolor feugiat placerat. Suspendisse enim turpis, imperdiet in tellus sit amet, consectetur porta magna. Suspendisse odio nulla, imperdiet eget augue in, pulvinar hendrerit nunc. Aenean ut cursus tellus, nec vehicula ante. Vestibulum ornare erat non ante tempus, eu aliquet felis dapibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris eget arcu imperdiet, laoreet erat non, imperdiet leo. Sed arcu mi, ornare non leo sed, faucibus semper nunc.
result:
Снимок экрана от 2017-12-03 17-12-23.png


Thanks: ZennoScript[/TD][/TR]
[TR][TD]Search for a word starting with a specific text (Thank ZennoScript for the modification)
Код:
Развернуть Свернуть Копировать
(?i)\bgo.*?(?=\W|\ |\r|\n|$)
Find in the text all the words beginning with go, for example: goal, god, google

Thanks: CSS, ZennoScript[/TD][/TR]
[TR][TD]Searches for a number in the range 400-699:
Код:
Развернуть Свернуть Копировать
^([4-6][0-9][0-9])$
more about the range you can see here http://www.regular-expressions.info/numericranges.html

Shared: CSS[/TD][/TR]
[TR][TD]Virtual columns with separator ";"
Код:
Развернуть Свернуть Копировать
(?<=(^|;)).*?(?=(;|$|\r\n))
initial data: name;pass;mail
result: the "column" you need by the match number:
Посмотреть вложение 8857
use case: we work with the list, we disassemble by the pieces of the column as in the table

Shares: CSS[/TD][/TR]
[TR][TD]Get the file name from the windows path:
Код:
Развернуть Свернуть Копировать
([^\\]+$)
initial data:
С:\Program Files (x86)\ZennoLab\ZennoPoster Pro\Progs\ZennoPoster.exe
result: ZennoPoster.exe

Shared: CSS[/TD][/TR]
[TR][TD]Search for strings NOT containing the specified (sub) string:
Код:
Развернуть Свернуть Копировать
(?<=(^|\r\n))((?!(test)).)*(?=($|\r\n))
initial data:
result:

Shared: CSS[/TD][/TR]
[TR][TD]Take all the lines of more than 18 characters
Код:
Развернуть Свернуть Копировать
(?<=(\r\n|^)).{18,}(?=(\r\n|$))

Thanks: alekwuy[/TD][/TR]
[TR][TD]Get all lines less than 18 characters
Код:
Развернуть Свернуть Копировать
(?<=(\r\n|^)).{1,18}(?=(\r\n|$))

Thanks: alekwuy[/TD][/TR]
[TR][TD]Search all HTML tags
Код:
Развернуть Свернуть Копировать
<.*?>
Use case - clear text from HTML code

Thanks: Trader1985[/TD][/TR]
[TR][TD]Find all empty lines in the text
Код:
Развернуть Свернуть Копировать
\n\r
Use case - text correction

Thanks: Trader1985[/TD][/TR]
[TR][TD]Search from three or more blank lines
Код:
Развернуть Свернуть Копировать
(?<=(\r\n){2})(\r\n){1,}
Use case - text correction if we are satisfied with 2 blank lines

Thanks: Trader1985[/TD][/TR]
[TR][TD]Email:
Код:
Развернуть Свернуть Копировать
[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?[\.A-Za-z0-9]{2,}
[/TD][/TR]
[TR][TD]IP
Код:
Развернуть Свернуть Копировать
(\d{1,3}\.){3}\d{1,3}
[/TD][/TR]
[TR][TD]URL
Код:
Развернуть Свернуть Копировать
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?
[/TD][/TR]
[TR][TD] IP:PORT (for example for parsing a proxy)
Код:
Развернуть Свернуть Копировать
(\d{1,3}\.){3}\d{1,3}:\d*
Thanks: up_lvl[/TD][/TR][/TBODY][/TABLE]


Origin: Link
Author: CSS
Translate by: LightWood
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)