当前位置:网站首页>Regular expression small example - get number character and repeated the most
Regular expression small example - get number character and repeated the most
2022-08-05 06:12:00 【CrazyQiQi】
Get the most repeated characters and their number from a random string through regular expressions
//First declare and define a random stringvar str = 'hgldsfkjhgkejhgkjg4654dfhghjf45gfgdrg4GJHGJK5dzfdf241b35sf';//1. Cut each character into an arrayvar arrStr = str.split('');//2. Sort character dataarrStr = arrStr.sort();//3. Assemble the sorted character data into a stringstr = arrStr.join('');var result = ''; //returns the most lettersvar count = 0; //counter//4. Capture group - the content matched by the expression in the regular expression, //Save to memory in a numbered or explicitly named group for later referencevar reg = /(\w)\1+/gi; //capturing group//Use replace to get the maximum number of charactersstr.replace(reg, function($0, $1) { //Collection: $0 represents a string of concatenated characters, $1 represents the first letter in a continuous stringif (count < $0.length) {result = $1;count = $0.length;}})console.log(" characters are: " + result + " , there are" + count + "");
The concept of capturing groups: Use regular expressions correctly to capture and non-capturing groups
边栏推荐
- Image compression failure problem
- 运维工程师,快来薅羊毛
- 解决这三大问题,运维效率将超90%的医院
- spark source code - task submission process - 2-YarnClusterApplication
- 正则表达式小示例--获取重复最多的字符及其数量
- 不吹不黑,这的确是我看过微服务架构最好的文章!
- spark source code - task submission process - 5-CoarseGrainedExecutorBackend
- 专有宿主机CDH
- Three modes of vim
- 你要找的cocos面试答案都在这里了!
猜你喜欢
spark源码-RPC通信机制
Unity3D中的ref、out、Params三种参数的使用
[Day6] File system permission management, file special permissions, hidden attributes
lvm逻辑卷及磁盘配额
[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data
线上问题排查流程
硬核!Cocos开发面试必备十问,让你offer拿到手软
技术分享杂七杂八技术
【Day5】软硬链接 文件存储,删除,目录管理命令
OpenCV3.0 is compatible with VS2010 and VS2013
随机推荐
Cocos Creator小游戏案例《棍子士兵》
图片压缩失效问题
快问快答—腾讯云服务器常见问题解答
Wireshark抓包及常用过滤方法
ACLs and NATs
LeetCode面试题
lvm逻辑卷及磁盘配额
2020年手机上最好的25种免费游戏
正则表达式小实例--去掉字符串中间和两边的空格
小度 小度 在呢!
论那些给得出高薪的游戏公司底气到底在哪里?
Account and Permission Management
Getting Started 05 Using cb() to indicate that the current task is complete
Contextual non-local alignment of full-scale representations
添加新硬盘为什么扫描不上?如何解决?
spark source code - task submission process - 1-sparkSubmit
The problem of calling ds18b20 through a single bus
入门文档01 series按顺序执行
偷题——腾讯游戏开发面试问题及解答
腾讯云消息队列CMQ