u013179958
CSDNRGY
2017-01-09 00:49
采纳率: 99.5%
浏览 4.0k

正则表达式如何实现,匹配以*开头的一行?

匹配下面代码中以*开头的行

 public class TransferForm extends BaseObject{
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID
     *
     * @mbggenerated Wed Jan 04 13:58:02 CST 2017
     */
    private String formId;

}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • showbo
    已采纳

    /^\s**[^\n]+$/gm,记得加m选项,多行匹配

    
    <textarea id="ta">
        public class TransferForm extends BaseObject{
        /**
        * This field was generated by MyBatis Generator.
        * This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID
        *
        * @mbggenerated Wed Jan 04 13:58:02 CST 2017
        */
        private String formId;
    
        }
    </textarea>
    <script>
        var s = ta.value, mc = s.match(/^\s*\*[^\n]+$/gm);
        console.log(mc)
    </script>
    
    点赞 评论
  • tang_cheng
    tang_cheng 2017-01-09 00:57

    正则表达式为:^\s**

    点赞 评论
  • jane_pop
    Jane_pop 2017-01-09 01:18

    [test@localhost shell]$ cat test.txt
    public class TransferForm extends BaseObject{
    /**

    • This field was generated by MyBatis Generator.
    • This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID *
    • @mbggenerated Wed Jan 04 13:58:02 CST 2017 */ private String formId;

    }
    [test@localhost shell]$ cat test.txt |sed 's/^[[:space:]]*//g'|grep '^*'

    • This field was generated by MyBatis Generator.
    • This field corresponds to the database column GC_TRANSFER_FORM.FORM_ID *
    • @mbggenerated Wed Jan 04 13:58:02 CST 2017 */_

    cat test.txt |sed 's/^[[:space:]]*//g'|grep '^*'
    先将行首的空格都去掉,之后筛选出以*开头的行。
    不知道你是不是这意思~~~

    点赞 评论

相关推荐