Perl模式匹配 [英] Perl pattern matching

查看:80
本文介绍了Perl模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一串字符ex:fhjhejfherhfehkehkeh


我想保留第一个h并删除所有其他字符我该怎么办?

I have a string of characters ex: fhjhejfherhfehkehkeh

I want to retain the first "h" and delete all the other characters how do i do it ?

推荐答案

到目前为止你尝试了什么?我们希望看到你走的路,而不仅仅是给你代码。这是一种更好的学习方式。那么,我们可以指导你。


问候,


杰夫
What have you tried thus far? We would like to see what road you are going down instead of just giving you the code. Its a better way to learn. Then, we can guide you.

Regards,

Jeff


从我开始perl的一个新手。

我知道如何删除第一个?h?字符并保持原样,使用^

但我想知道如何我做的反过来就是保持第一个?h?字符并删除剩余的h字符。字符
To start with i am a newbie in perl.
I am aware of how to delete the first ?h ?character and keep the remaining as it is, using ^
But I wanted to know how I do the inverse of this i.e keep the first ?h? character and remove the remaining "h" characters


正则表达式:s /(.* h [^ h] *)h /
regex: s/(.*h[^h]*)h/


这篇关于Perl模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆