First, some basic regular expression syntax, without the use of any one language, use notepad ++ to operate regular expression.
- Regular Expressions: Regular expression operating a regular expression is a string, the regular expression uses special notation.
Regular expression operation on a string of mainly focused on what applications:
- match
- Cutting
- replace
- Seek
Predefined character (note: do not add any predefined character can only match one character before quantifier, such
"12"
can not be "\\d
" match):.
Represent any character (with a line terminator may or may not match the match)\d
digital:[0-9]
\D
Non-numeric characters:[^0-9]
\s
Whitespace characters:[\t\n\xoB\f\r]
\S
Non-whitespace characters:[^\s]
\w
Word character:[a-zA-Z_0-9]
that is, including az, AZ, 0-9, underscore.
Quantifier:
X?
X, once or not even onceX*
X, zero or more timesX+
X, one or more timesX{n}
X, exactly n timesX{n,}
X, at least n timesX{n,m}
X, at least n times, but not more than m times
The scope of the word (can only match one character):
[abc]
a, b or c[^abc]
Any characters, in addition to a, b or c[a-zA-Z]
a to z or AZ, including two letters (range)[a-dm-p]
a through d, or m through p- Note: No matter how long the scope of the word in the content, with no quantifiers can only match one character only.
- Regular and reverse packet matches the reference expression
- If the regular content needs to be multiplexed, you need to group content regular. The purpose of the group is to increase the regular reusability. Neither group number is specified, the group number from the beginning.
- Description packet nesting relationship:
((A)(B(C)))
: A total of four groups, groups are No. 1((A)(B(C)))
, No. 2 group is a(A)
, group 3(B(C))
, group 4(C)
.\1
: Reference matched to the first set of content. In this case it is easy to see the nesting relationship. \1
Or$1
for content matching the first packet
\2
or$2
a content packet matches a first
...
\9
or$9
for content matching the first packet- Under normal circumstances we match any two identical characters you can use \ 1 or $ 1 to refer such as strings, etc.
"AA Am 99"
, and now repeat to match the characters, with the(\w)\1
regular expression can match the results:"AA", "99"
- Description:
(\w)
to match any character except newline and tab, and\1
is(\w)
a reference, so that you can be understood as:(\w)\1
is(\w)(\w)
, however ,(\w)\1
and(\w)(\w)
the difference is that,(\w)(\w)
on any two consecutive characters, such asAc, MM, K9,
may be, However,(\w)\1
onlyAA, CC, 99
such consecutive identical characters so you can understand,\1
is(\w)
an example of the reference, when(\w)
matched toA
the time,\1
is expressed asA
, when(\w)
matching9
the time,\1
is expressed as9
.
- Now with notepad ++ regular expression search content and the content in quotation marks.
- Now given data:
{"dev_id":C1088941,"time":2017-06-01T08:01:08,"voltage":215.67,"current":0.94,"speed":0,"status":false,
"temperature":25.3,"humdity":0.52},
{"dev_id":C1088941,"time":2017-06-01T08:11:02,"voltage":217.38,"current":0.69,"speed":0,"status":false,
"temperature":29.3,"humdity":0.48},
{"dev_id":C1088941,"time":2017-06-01T08:21:08,"voltage":211.83,"current":0.35,"speed":0,"status":false,
"temperature":31.9,"humdity":0.45},
{"dev_id":C1088941,"time":2017-06-01T08:31:02,"voltage":215.31,"current":0.40,"speed":0,"status":false,
"temperature":25.3,"humdity":0.45},
{"dev_id":C1088941,"time":2017-06-01T08:41:07,"voltage":211.72,"current":0.12,"speed":0,"status":false,
"temperature":30.4,"humdity":0.50},
{"dev_id":C1088941,"time":2017-06-01T08:51:05,"voltage":214.48,"current":0.36,"speed":0,"status":false,
"temperature":28.3,"humdity":0.46},
{"dev_id":C1088941,"time":2017-06-01T09:01:05,"voltage":217.45,"current":0.97,"speed":0,"status":false,
"temperature":32.9,"humdity":0.52},
{"dev_id":C1088941,"time":2017-06-01T09:11:01,"voltage":215.60,"current":0.83,"speed":0,"status":false,
"temperature":25.3,"humdity":0.48},
{"dev_id":C1088941,"time":2017-06-01T09:21:07,"voltage":215.98,"current":0.74,"speed":0,"status":false,
"temperature":27.2,"humdity":0.52},
{"dev_id":C1088941,"time":2017-06-01T09:31:04,"voltage":210.28,"current":0.81,"speed":0,"status":false,
"temperature":26.9,"humdity":0.48},
{"dev_id":C1088941,"time":2017-06-01T09:41:03,"voltage":216.37,"current":0.03,"speed":0,"status":false,
"temperature":32.2,"humdity":0.54},
{"dev_id":C1088941,"time":2017-06-01T09:51:06,"voltage":219.76,"current":0.03,"speed":0,"status":false,
"temperature":33.4,"humdity":0.51},
{"dev_id":C1088941,"time":2017-06-01T10:01:06,"voltage":216.27,"current":0.52,"speed":0,"status":false,
"temperature":25.3,"humdity":0.45},
{"dev_id":C1088941,"time":2017-06-01T10:11:02,"voltage":212.90,"current":0.38,"speed":0,"status":false,
"temperature":27.4,"humdity":0.47},
{"dev_id":C1088941,"time":2017-06-01T10:21:08,"voltage":216.21,"current":0.40,"speed":0,"status":false,
"temperature":33.2,"humdity":0.51},
{"dev_id":C1088941,"time":2017-06-01T10:31:03,"voltage":210.62,"current":0.48,"speed":0,"status":false,
"temperature":29.6,"humdity":0.51}"
Now put this date in the text data to find and double quotation marks, as shown:
{"dev_id":C1088941,"time":"2017-06-01T08:01:08","voltage":215.67,"current":0.94,"speed":0,"status":false,
"temperature":25.3,"humdity":0.52},
{"dev_id":C1088941,"time":"2017-06-01T08:11:02","voltage":217.38,"current":0.69,"speed":0,"status":false,
"temperature":29.3,"humdity":0.48},
{"dev_id":C1088941,"time":"2017-06-01T08:21:08","voltage":211.83,"current":0.35,"speed":0,"status":false,
"temperature":31.9,"humdity":0.45},
{"dev_id":C1088941,"time":"2017-06-01T08:31:02","voltage":215.31,"current":0.40,"speed":0,"status":false,
"temperature":25.3,"humdity":0.45},
{"dev_id":C1088941,"time":"2017-06-01T08:41:07","voltage":211.72,"current":0.12,"speed":0,"status":false,
"temperature":30.4,"humdity":0.50},
{"dev_id":C1088941,"time":"2017-06-01T08:51:05","voltage":214.48,"current":0.36,"speed":0,"status":false,
"temperature":28.3,"humdity":0.46},
{"dev_id":C1088941,"time":"2017-06-01T09:01:05","voltage":217.45,"current":0.97,"speed":0,"status":false,
"temperature":32.9,"humdity":0.52},
{"dev_id":C1088941,"time":"2017-06-01T09:11:01","voltage":215.60,"current":0.83,"speed":0,"status":false,
"temperature":25.3,"humdity":0.48},
{"dev_id":C1088941,"time":"2017-06-01T09:21:07","voltage":215.98,"current":0.74,"speed":0,"status":false,
"temperature":27.2,"humdity":0.52},
{"dev_id":C1088941,"time":"2017-06-01T09:31:04","voltage":210.28,"current":0.81,"speed":0,"status":false,
"temperature":26.9,"humdity":0.48},
{"dev_id":C1088941,"time":"2017-06-01T09:41:03","voltage":216.37,"current":0.03,"speed":0,"status":false,
"temperature":32.2,"humdity":0.54},
{"dev_id":C1088941,"time":"2017-06-01T09:51:06","voltage":219.76,"current":0.03,"speed":0,"status":false,
"temperature":33.4,"humdity":0.51},
{"dev_id":C1088941,"time":"2017-06-01T10:01:06","voltage":216.27,"current":0.52,"speed":0,"status":false,
"temperature":25.3,"humdity":0.45},
{"dev_id":C1088941,"time":"2017-06-01T10:11:02","voltage":212.90,"current":0.38,"speed":0,"status":false,
"temperature":27.4,"humdity":0.47},
{"dev_id":C1088941,"time":"2017-06-01T10:21:08","voltage":216.21,"current":0.40,"speed":0,"status":false,
"temperature":33.2,"humdity":0.51},
{"dev_id":C1088941,"time":"2017-06-01T10:31:03","voltage":210.62,"current":0.48,"speed":0,"status":false,
"temperature":29.6,"humdity":0.51}"
All such date plus the double quotes, like!