Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate random numbers using regular expressions

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How do I generate random numbers using regular expressions? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

Installation

Git clone https://github.com/GitHub-Laziji/reverse-regexp.gitcd reverse-regexpmvn install org.laziji.commons reverse-regexp 1.0-SNAPSHOT

Use

Random character syntax

Matching syntax that supports most regular expressions

\ d number, equivalent to [0-9]

\ W numbers and letters are underlined, which is equivalent to [0-9aMuz Amurz]

\ s white space character, containing only spaces and tabs

. For any character except\ n and\ r, random characters are generated only between ascii codes 0,255

[a-zA-Z A / B] range, ^ syntax is not supported

And other characters.

Repetitive printing syntax

Same as repeated matching syntax for regular expressions

? Randomly generate 0 or 1 character

* more than 0 characters are randomly generated, with a maximum of 16 characters by default

+ randomly generate more than 1 character, up to 16 by default

{n} generate n characters

{n,} randomly generate n ~ characters, up to a maximum of max (16 ~ n) by default

{ncentine m} randomly generate nomenm characters

Other grammars

| | or syntax, such as aaa | bbb | ccc randomly generates aaa or bbb or ccc with equal probability |

() support parentheses

Public class MainTest {@ Test public void test () throws RegexpIllegalException, UninitializedException, TypeNotMatchException {random ("\ w {6 cn 12} @ [a-z0-9] {3}\. (com | cn)", "mailbox"); random ("1 (3 | 5 | 7 | 8)\\ d {9}", "Mobile number"); random ("-? [1-9]\\ d *\.\\ d +", "floating point number") Random ("https?:// [\\ w -] + (\\ .[\\ w -] +) {1meme2} (/ / [\\ w -] {3pyrr6}) {0meme2} (\\? [\\ w_] {4pyr6} = [\\ w_] {4pr _ 6} (& [\\ w_] {4pr _ 6} = [\\ w_] {4pm _ 6})?", "URL") } private void random (String expression, String title) throws RegexpIllegalException, TypeNotMatchException, UninitializedException {System.out.println (title + "+ expression); Node node = new OrdinaryNode (expression); Pattern pattern = Pattern.compile (node.get_Expression ()); for (int I = 0; I < 10; iTunes +) {String data = node.random () System.out.println ("[" + pattern.matcher (data) .matches () + "]" + data);} System.out.println ();}}

Output

Email address\ w {6pm 12} @ [a-z0-9] {3}\. (com | cn)

[true] 19cZ8eISNA@9je.com

[true] xpv3wJ@i3h.cn

[true] 6qDUfY@1g9.com

[true] iVnZSMA373@6zd.cn

[true] I5wiX97@ffe.cn

[true] mwqA5sXQ@g8j.cn

[true] HUXiCem1Y0w@j98.cn

[true] 1jOQWsELF@u1o.cn

[true] _ Q4QTvxPeMFh@bds.com

[true] 3xFH33Aa@6lh.cn

Mobile number 1 (3 | 5 | 7 | 8)\ d {9}

[true] 18263364656

[true] 17539493178

[true] 17452542895

[true] 15190699623

[true] 13441385631

[true] 15450856416

[true] 18651247283

[true] 13835809899

[true] 18595798569

[true] 17115703866

Floating point number -? [1-9]\ d *.\ d +

[true] 8148340336.1501586550282701

[true]-3339660539.406

[true]-51.6120243661611419

[true]-731621835440468.9708278

[true]-27438753435.9137579

[true] 393811376.777268751417

[true] 3286498432415.3962664603

[true]-5299652275.9

[true] 216.93676279820770

[true] 34.36843273

URL https?:// [\ w -] + (\ .[\ w -] +) {1Magne2} (/ [\ w-] {3reagen6}) {0jing2} (\? [\ w_] {4pr _ 6} = [\ w_] {4pr _ 6} (& [[\ w_] {4pr _ 6})) {0jue 2})?

[true] https://a_fl.thx/4_4

[true] http://v3YTuJ0Gu-5z8.JGhpdLe/V2j/ndL-UO

[true] https://FuMG-gafEc.R2FRRtLyX/ahg

[true] https://5phYVK9.wh7vl9z3AAZVg.z-yQSiMTdQw8S9-/WKCd

[true] https://T9dntbI.4Su8vxYhCr6?T85gV=R6TYtm&1c97x=nCTyA5

[true] http://qHyDgqBtYwq6Stg8.I6gb-M_ripkiEafK?ZLxy=Itny&RmsTX=X7KEuW&bwuk2=frcjO6

[true] http://UJ.Yb3foKTJKy-uqKUl.ZXrrFUk9K/Dcymu?W2tasq=oqzS&hYGWD=MF6l&FMHOi=F6ct8T

[true] https://BY_iS.tnlclAvxMkuO.T90G5XETj/cQncGI

[true] http://hG.li8Nzv.uaGokB/CTnrqp

[true] https://huZmN.v-LtoY/Dyl/peq?NUmt=__QDXG&8GBY=wZ8M&AkKZl4=8NZfEt

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report