当前位置:网站首页>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
边栏推荐
- 【机器学习】1单变量线性回归
- To TrueNAS PVE through hard disk
- [Paper Intensive Reading] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation (R-CNN)
- 入门文档06 向流(stream)中添加文件
- 成功的独立开发者应对失败&冒名顶替综
- 【Day6】文件系统权限管理 文件特殊权限 隐藏属性
- Getting Started Documentation 12 webserve + Hot Updates
- D39_向量
- 入门文档11 自动添加版本号
- Unity3D中的ref、out、Params三种参数的使用
猜你喜欢
随机推荐
D39_欧拉角与四元数
Unity物理引擎中的碰撞、角色控制器、Cloth组件(布料)、关节 Joint
Unity中的GetEnumerator 方法及MoveNext、Reset方法
Dsf5.0 bounced points determine not return a value
论那些给得出高薪的游戏公司底气到底在哪里?
【Day8】Knowledge about disk and disk partition
spark operator - map vs mapPartitions operator
Unity3D中的ref、out、Params三种参数的使用
微信小程序页面跳转传参
TCP/IP四层模型
【Day8】(超详细步骤)使用LVM扩容
LeetCode面试题
spark源码-任务提交流程之-5-CoarseGrainedExecutorBackend
入门文档11 自动添加版本号
入门文档05 使用cb()指示当前任务已完成
入门文档10 资源映射
【Day8】 RAID磁盘阵列
spark源码-任务提交流程之-1-sparkSubmit
vim的三种模式
CIPU,对云计算产业有什么影响









