12. Regular _pdf bookmark plus page number

Source: Internet
Author: User

Add a page number to the back of the bookmark, like this:        
s = "\t\t1.12 first section \t36", equivalent to the last \ T location plus page numbers, you can:
① can reverse the string, and then Str.split () once, plus the page number; ② uses Re.split () to locate the last \ T, split
  
 
  1. #!/usr/bin/python
  2. #coding:utf-8
  3. #2015-12-22 11:53:30.469000
  4. """
  5. """
  6. import sys
  7. reload(sys)
  8. sys.setdefaultencoding(‘utf8‘)
  9. import re
  10. s = "\t\t1.12 第一节\t36"
  11. pat = r"\t(?=\d+$)"
  12. print re.split(pat,s)
  13. ‘‘‘
  14. re.split(pattern, string, maxsplit=0, flags=0)
  15. 会用pattern匹配到的字符作为分隔符,对string进行分割,产生一个list,list里没有分割符;
  16. 如果pattern里有圆括号(组),分隔符也会作为组出现在结果的list里;
  17. pat = r"\t(?=\d+$)" [‘\t\t1.12 zhang‘, ‘36‘]
  18. 匹配到最后一个"\t"
  19. pat = r"\t(\d+$)" [‘\t\t1.12 zhang‘, ‘36‘, ‘‘]
  20. 匹配到了最后的"\t"和"36",36在括号里是组,所以显示出来;
  21. pat = r"\t(?:\d+$)" [‘\t\t1.12 zhang‘, ‘‘]
  22. 匹配到了"\t36"
  23. ‘‘‘






From for notes (Wiz)

12. Regular _pdf bookmark plus page number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.